English 中文(简体)
Parse Json to Java bean same field different category
原标题:Parse Json to Java bean same field different type
  • 时间:2010-09-21 08:09:16
  •  标签:
  • json

I have a bean structure to parse JSon files. I am facing one problem, to the same fild, I find two different data types in two different JSon files.
String array

"Keywords": ["90NSB12596","Slam","Dunk","FullBodyIsolated","Action"],  

努力

"Keywords": "Basketball|NBA",

我如何区分这两个档案? 我的灯塔是:

public String[] getKeywords2() {
        return keywords2;
    }
    @JsonProperty("Keywords")
    public void setKeywords2(String[] keywords2) {
        this.keywords2 = keywords2;
    }
    public String getKeywords() {
        return keywords;
    }
    @JsonProperty("Keywords")
    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }
    public String getCaptionAbstract() {
        return captionAbstract;
    }

Of course this is wrong, I would like to find the way to different theese two @JsonProperty("Keywords")
Thanks in advance

最佳回答

I decided to find a easy and quick solution.
Add @JsonIgnoreProperties(ignoreUnknown=true) in th ebeggining of the bean, so the program just ignore this field.
I would like to know if there is a better solution, so if someone has another idea, please let me know!

增 编

问题回答

暂无回答




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签