Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot serialize enum with Jackson and Jaxb annotation using @XmlEnumValue
    primarykey
    data
    text
    <p>I am using Jackson 2.2.2 with JAXB annotated classes. I would like to get enums serialized as int numbers. Because of the XML (as I want the same behaviour for XML as well) there is necessity to use @XmlEnumValue etc. All fine. For serialization to JSON this annotation according the documentation of Jackson is supported but so far no luck to make it work for JSON (XML is fine).</p> <pre><code>@XmlType(name = "Period") public enum Period { @XmlEnumValue("11") DAILY("Daily"), @XmlEnumValue("1") WEEKLY("Weekly"), @XmlEnumValue("2") SEVENTH_DAY("3"); private final String value; ... </code></pre> <p>Produced JSON still looks following:</p> <pre><code> "OvertimeRates": { "DAILY": [ { "AfterHours": -19497, "Rate": 3.7003279564106983 } ] }, </code></pre> <p>While I would expect that instead DAILY I would see 11.</p> <p>My Code:</p> <pre><code> mapper = new ObjectMapper(); JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule(); mapper.registerModule(jaxbAnnotationModule); mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); // mapper.configure(SerializationFeature.WRITE_ENUMS_USING_INDEX, false); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); final PosData posData = dataGenerator.getPosData(); try { mapper.writeValue(new File(PATH_TO_FILE), posData); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>I tried to experiment with mapper.configure(SerializationFeature.WRITE_ENUMS_USING_INDEX, false); but that didn't help either.</p> <p>Any idea what I've missed?</p> <p>Ta</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