Note that there are some explanatory texts on larger screens.

plurals
  1. POJson Jersey Deserialize : Abstract Class
    primarykey
    data
    text
    <p>I'm trying to deserialize some JSON with Jersey/Jackson in Java.</p> <p>Here is an example of my JSON</p> <pre><code> { "text":"toto", "link":"titi", "items":[{ "text":"toutou", "link":"tata", "items":[{ "text":"toto2", "link":"toutou2", "data":"tonti", ]} ]} } </code></pre> <p>So what my Java model parts looks like this</p> <pre><code>public IItem { ... } public Item implements IItem { List&lt;IItem&gt; items; String text; String link; ... } public ItemData extends Item { String data; ... } </code></pre> <p>Now, when i try to deserialize my JSON, object mapper doesnt know what concrete class to Use. How do I tell him this ? The thing is that I want an Item (with a list of Item (with a list of ItemData)).</p> <p>I've though of only using one object containing all fields (text, link, data), but i'd prefer this type of design which appears better me. Do you think it's worth it ?</p> <p>In reality I have more than one field that would replicate because JSON structure is a bit more complex, I've simplified it for sake of clarity. </p> <p><strong>Question2</strong> : After that i need to serialise my objects again in JSON (first part is only for temporary development, I'll be filling objects from a JDBC driver later on), how can I tell jersey to only display one level at the time ?</p> <p>i.e i request <code>/</code> I want the first level only, answer should be :</p> <pre><code> { "text":"toto", "link":"titi", "items":[{ "text":"toutou", "link":"tata", ]} } </code></pre> <p>and if i request <code>/tata</code> answer should be :</p> <pre><code> { "text":"toutou", "link":"tata", "items":[{ "text":"toto2", "link":"toutou2", "data":"tonti" ]} } </code></pre> <p>(Question is more about how hiding the second level in my first request, I do understand how to handle the second request).</p> <p>Thanks,</p>
    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.
    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