Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to parse JSON array response using Jackson?
    primarykey
    data
    text
    <p>I'm building a RESTful client for Android and I have a question about Jackson.<br> I get the following JSON response:</p> <pre><code>{ "cars": [ { "active": "true", "carName": "××× ×'פ ס××××§×", "categoryId": { "licenseType": "××××××", "licenseTypeId": "1" }, "id": "1401268", "insuranceDate": "2011-07-05T00:00:00+03:00", "lessonLength": "45", "licenseDate": "2011-07-05T00:00:00+03:00", "price": "100", "productionYear": "2009-07-05T00:00:00+03:00" }, { "active": "true", "carName": "××©× ×××", "categoryId": { "licenseType": "×ש××ת", "licenseTypeId": "4" }, "id": "1589151", "insuranceDate": "2011-04-13T00:00:00+03:00", "lessonLength": "30", "licenseDate": "2011-04-13T00:00:00+03:00", "price": "120", "productionYear": "2004-04-12T00:00:00+03:00" },............. etc </code></pre> <p>each is a car from a class that looks like this:</p> <pre><code>public class Cars implements Serializable { private static final long serialVersionUID = 1L; private Integer id; private String carName; private Date productionYear; private Date insuranceDate; private Date licenseDate; private Boolean active; private Long price; private Integer lessonLength; private Date dayStart; // private Collection&lt;Students&gt; studentsCollection; // private Collection&lt;Lessons&gt; lessonsCollection; private LicenseTypes categoryId; // private Collection&lt;Kilometers&gt; kilometersCollection; public Cars() { } public Cars(Integer id) { this.id = id; } public Cars(Integer id, String carName) { this.id = id; this.carName = carName; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } } </code></pre> <p>I've been trying to parse it automatically with Jackson with little/no success.. Is it even possible to parse and convert it to an object automatically? I can't find this anywhere online..<br> If you have some sort of example for this specific type of server response please point me there, or if someone can generally explain how to do it with Jackson or with some other tool, I would greatly appreciate it.</p> <hr> <p>EDIT: Thanks all. I managed to make Jackson work by removing the <code>{"cars":</code> from the beginning of the result string, and the <code>}</code> from the end of the result string. After doing that, Jackson understood it was an array and did everything by itself. So for anyone else who got problems with those sort of things: A JSON array should start with <code>[</code> and end with <code>]</code> and each element inside should start with <code>{</code> and end with <code>}</code>. No annotations needed, Jackson can find the members by itself.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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