Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat ObjectMapper config / annotations required for successful JSON / JSON array exhange using Jackson 2.2
    primarykey
    data
    text
    <p>Using Jackson 2.2.2 and Apache CXF web services client and server API. I'm finding it impossible to serialize / deserialize JSON without failure.</p> <p>Java class:</p> <pre><code>MyPojo { ..... various properties } </code></pre> <p>JSON produced from Jackson:</p> <pre><code>{ "MyPojo": { ..... various properties } } </code></pre> <p>When I send the exact same JSON back to Jackson for it to consume, it fails with:</p> <pre><code>com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "MyPojo" (class app.model.MyPojo), not marked as ignorable (17 known properties: ,..... </code></pre> <p>Ideally, Jackson would not wrap the MyPojo object with {"MyPojo":} because I only ever exchange MyPojo objects, so it is implied. To that end, how can I get Jackson to produce:</p> <pre><code>{ ..... various properties } </code></pre> <p>Then, how do I get jackson to consume the same JSON without failing? i.e. what ObjectMapper configuration or annotations or combination of both do I have to use?</p> <p>If this is impossible, then how do I configure / annotate to get Jackson to consume the "wrapped" JSON without failing?</p> <p>ALSO,</p> <p>I have the same issues when producing / consuming an array of MyPojo objects:</p> <p>JSON produced from Jackson:</p> <pre><code>{ "MyPojo": [ { ..... various properties }, { ..... various properties } ] } </code></pre> <p>..when consumed fails with: </p> <pre><code>com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of app.model.MyPojo[] out of START_OBJECT token </code></pre> <p>Again, ideally (but not essential) Jackson would produce / consume:</p> <pre><code>[ { ..... various properties }, { ..... various properties } ] </code></pre> <p>Note, the Apache CXF WS appears to perform some magic via its @GET, @POST, etc, annotations as when used in conjuntion with a RESTful WS resource method which returns a MyPojo object, i.e. it appears that after my method returns the object, it is transformed into JSON.</p> <p>To that end, I am unsure if a local or even global ObjectMapper will influence the output, so this should also be considered when answering.</p> <p>Another note, I also need the same POJO to be produced and consumed in XML via JAXB.</p> <p>EDIT: I am now quite certain that TomEE/CXF is not using Jackson and that this is the cause of my issues. I'll update when I get it to work.</p> <p>RESOLVED: Further investigation revealed that whilst the JSON was being deserailized by Jackson, the default Jettison provider was not being overriden with Jackson when serializing due to misconfiguration of default JSON provider in CXF/TomEE. This resulted in a Jackson - Jettison formatting mismatch.</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.
    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