1

i have a json structure as follows

[
  {
    "tag10": "10",
    "tag12": "10",
    "tag13": "10",
    "tag14": "10"
  },
   {
    "tag10": "11",
    "tag12": "11",
    "tag13": "11",
    "tag14": "11"
  },
    {
    "tag10": "12",
    "tag12": "12",
    "tag13": "12",
    "tag14": "12"
  }
]

what can be the best way to deserilize and unwrap this array of objects as following can be the bean class

public class Abc
{
    private String tag13;

    private String tag14;

    private String tag10;

    private String tag12;

    public String getTag13 ()
    {
        return tag13;
    }

    public void setTag13 (String tag13)
    {
        this.tag13 = tag13;
    }

    public String getTag14 ()
    {
        return tag14;
    }

    public void setTag14 (String tag14)
    {
        this.tag14 = tag14;
    }

    public String getTag10 ()
    {
        return tag10;
    }

    public void setTag10 (String tag10)
    {
        this.tag10 = tag10;
    }

    public String getTag12 ()
    {
        return tag12;
    }

    public void setTag12 (String tag12)
    {
        this.tag12 = tag12;
    }
}

1 Answer 1

1

Use this code to deserilize Json:

List<Abc> data = new ObjectMapper()
                                    .readValue(
                                            JSONSTRING,
                                            new TypeReference<List<Abc>>() {
                                            });

now data have a list of Abcs.

Sign up to request clarification or add additional context in comments.

3 Comments

what will be the TypeReference here?? will it be a class which is having a liat of Abc
It is Refrence of type in com.fasterxml.jackson.core.type.TypeReference.TypeReference package. you should import jackson.core .jar file to your project
there is a problem with my response when data is present in the response i got JSON Array of JSON objects but when data is not present the i got Empty JSON Object how can i handle this ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.