Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you used JAXB to generate your classes, you can certainly have something like @XmlElements with different types to parse a List. </p> <p>Now, if you are also using the same JAXB classes with Jersey/Jackson, you can enhance the metadata of the class by adding @JsonTypeInfo and @JsonSubTypes to describe how to format the name of the List/Array of objects. </p> <p>While @JsonTypeInfo describes the type to be added, the @JsonSubTypes gives the options of the enclosed collection. For instance, As.PROPERTY to define a property of the output, as displayed in the example below, where a list of entities that can have elements of different types, including the type itself ("Form") in addition to 2 other types "Field" and "Table".</p> <pre><code>public class Form { @XmlElements({ @XmlElement(name = "field", type = Field.class), @XmlElement(name = "form", type = Form.class), @XmlElement(name = "table", type = Table.class) }) @JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "obj") @JsonSubTypes({ @JsonSubTypes.Type(value = Field.class), @JsonSubTypes.Type(value = Form.class), @JsonSubTypes.Type(value = Table.class) }) @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-11-11T02:08:36-08:00", comments = "JAXB RI v2.2.4-2") @JsonProperty("entities") protected List&lt;Object&gt; fieldOrFormOrTable; </code></pre> <p>The serialization of the object using Jersey's Jackson default serializers with the added metadata will be the following... </p> <pre><code> "entities": [ { "obj": "Table", "row": { "id": 1, "fields": [ { "id": "DEBUGARY", "type": "Text", "kind": "user" } ] }, "id": "DBGARRAY" }, { "obj": "field", "id": "IDBG", "type": "Text", "kind": "user" }, ..., ..., ...] </code></pre>
 

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