I have a library of objects, whose source code is not editable so cant annotate them, is there another way to config Jackson Mapper like via XML.
Mapping XML Property (Attribute / Element) Annotation @JacksonXmlProperty can be used to provide XML-specific configuration for properties, above and beyond what @JsonProperty contains. It is an alternative to using JAXB annotations. Using boolean property isAttribute can control if the target property is attribute or XML element.
Jackson Annotations for Serialization. The Jackson XML module supports the full range of annotations that Jackson provides for annotating our POJOs. This means that we can have one single set of beans, with one set of annotations and, depending on the ObjectMapper instance, we select whether we get XML or JSON.
Starting with version 2, it has also introduced a mature XML implementationalongside its established JSON support. Adding Jackson XML to the Project Adding the Jackson XML module to the project only needs a single dependency – the Jackson XML module itself:
The absolute simplest way of working with this is to just use the default configuration: ObjectMapper objectMapper = new XmlMapper(); However, if we need additional configuration, we can instead construct the Jackson Module manually and set it up as necessary:
What do you want to configure? Often there isn't need to configure anything.
One way to use annotations without modifying value classes is to use "mix-in annotations" (see, for example this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With