Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting JSON array to POJO using jackson object mapper
    primarykey
    data
    text
    <p>This is possibly a duplicate question.. please refer this <a href="https://stackoverflow.com/q/7045836/2219600" title="this text appears when you mouse over">link</a>.<br> I am able to map one json object to POJO.But how can i convert array of json object to pojo using the same jackson framework.</p> <pre><code>private void jsonToPojo(){ ObjectMapper mapper=new ObjectMapper(); try { User1 user1=mapper.readValue(readFromFile(), User1.class); User1[] user2=mapper.readValue(readFromFile(), User1[].class); System.out.println(user1); Toast.makeText(getApplicationContext(), "inside try", 0).show(); } catch (JsonParseException e) { // TODO Auto-generated catch block Log.i("Exception", "jsonparseexception"); e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block Log.i("Exception", "jsonmapping exception"); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block Log.i("Exception", "ioexception"); e.printStackTrace(); } } </code></pre> <p>This is the class user object.</p> <pre><code>public class User { private int age = 23; private String name = "amal"; private List&lt;String&gt; messages = new ArrayList&lt;String&gt;() { { add("hi"); add("how"); add("are u."); } }; //getter and setter methods @Override public String toString() { return "User [age=" + age + ", name=" + name + ", " + "messages=" + messages + "]"; } </code></pre> <p>This is what i tried to do:(readFromFile() takes json from a file)</p> <pre><code>User1[] user2=mapper.readValue(readFromFile(), User1[].class); </code></pre> <p>The jsonToPojo() is working well for only one object. However, if i try the above line of code,its not taking the following json:</p> <pre><code>[ { "age":"23", "messages":["hi","how","are u."], "name":"amal" }, { "age":"98", "messages":["Reply","my","question"], "name":"You" } ] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload