jackson-dataformat-xml

Dynamic root element with Jackson

淺唱寂寞╮ 提交于 2021-02-11 06:44:13
问题 I'm currently working on a project that deals with elements that (for legacy reasons) must have a tag name that represents their type. Basically I have this: @JsonRootName("node") class NodeDocument { private String type; } Which outputs something like: <node type="someType"></node> But what's expected would be: <someType></someType> @JsonRootName doesn't seem to be usable on a method or attribute. Even though there is SerializationConfig.withRooName() or custom serializers, I can't seem to

Dynamic root element with Jackson

不羁岁月 提交于 2021-02-11 06:43:10
问题 I'm currently working on a project that deals with elements that (for legacy reasons) must have a tag name that represents their type. Basically I have this: @JsonRootName("node") class NodeDocument { private String type; } Which outputs something like: <node type="someType"></node> But what's expected would be: <someType></someType> @JsonRootName doesn't seem to be usable on a method or attribute. Even though there is SerializationConfig.withRooName() or custom serializers, I can't seem to

how to deserialize xml element without tag using jackson

混江龙づ霸主 提交于 2021-01-29 13:17:51
问题 I want deserialize below xml <Test> <message num="90">[WANT TO EXTRACT THIS DATA] <care>test data 1</care> <care>test data 2</care> </message> </Test> Having structure like below @JacksonXmlRootElement(localName = "Test") public class Policy { @JacksonXmlProperty(localName = "message ") private final Message message; //builders } In message class I having like below public class Message{ @JacksonXmlProperty(localName = "care") private final List<String> care; //builders } Now I want to

Jackson xml 2.9.0: @JacksonXmlElementWrapper not working with @JsonCreator & @JsonProperty constructor

时光总嘲笑我的痴心妄想 提交于 2021-01-29 03:06:26
问题 I would like that my ParentClass has final fields, 'brokenChildList' list is wrapped xml element and list items have different tag than the list ( <brokenChildList><brokenChild/></brokenChildList> ). Here is a snippet of code to reproduce my issues (imports are partially truncated, setters and getters omitted) import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml

Jackson XML to JSON converter removes multiple child records

别说谁变了你拦得住时间么 提交于 2021-01-27 05:21:45
问题 I am using following code to convert my source XML to JSON. However, this code removes any multiple occurrence of child records in source XML and output JSON only contains last child record. How do I get Jackson XML to JSON converter to output all child records in JSON? Code XmlMapper xmlMapper = new XmlMapper(); Map entries = xmlMapper.readValue(new File("source.xml"), LinkedHashMap.class); ObjectMapper jsonMapper = new ObjectMapper(); String json = jsonMapper.writer().writeValueAsString

Parsing XML to Java Object Node

无人久伴 提交于 2021-01-03 06:44:45
问题 Currently I'am facing problem when trying to parse a xml document to a Java Object. The only necessary information which i want to keep is the iid and time list. xml test file: <items> <item> <iid>14</iid> <options> <option> <times> <time> <timeentry>20200714100100</timeentry> <timetill>20200714101500</timetill> <timemaxcount>2</timemaxcount> </time> <time> <timeentry>20200714101600</timeentry> <timetill>20200714103000</timetill> <timemaxcount>2</timemaxcount> </time> <time> <timeentry

swagger codegen add @JacksonXmlElementWrapper(useWrapping = false) annotation to a single field

不羁的心 提交于 2020-03-26 03:21:28
问题 I'm currently using swagger codegen using yml to generate my models However I have one field, that is a List<Object> that needs to have the @JacksonXmlElementWrapper(useWrapping = false) . I can see the @JacksonXmlElementWrapper in POJO.mustache but not in model.mustache . Does anyone know what to add in the yaml file or anywhere else so that field gets generated with that annotation? Thanks. I'm using spring-java language with gradle. I need this to be generated during build. so minimal

How to control encoding with Jackson XmlMapper?

拥有回忆 提交于 2020-02-24 14:59:25
问题 I can't find a(n obvious) way to change the encoding for serialized XML from the default UTF-8 to ISO-8859-1 . I read the Usage Guide, which makes me think that there must be a way using XMLOutputFactory with XmlFactory to achieve this, but I can't see a way to configure any of those factories to use another encoding by default, there's only createXMLEventWriter where I could pass in an encoding. I know how to generate the XML declaration using ToXmlGenerator.Feature.WRITE_XML_DECLARATION .

Jackson XML: how to serialize empty/null collections as empty node

吃可爱长大的小学妹 提交于 2020-01-30 02:40:52
问题 I'm using Jackson XML 2.8.9 and unfortunately I cannot find any way to serialize empty/null collections as empty nodes. Method responsible for serializing to XML: protected byte[] toXml(final Collection<ReportView> reports) throws IOException { final XmlMapper mapper = new XmlMapper(); // place for code which will solve my problem return mapper.writerWithDefaultPrettyPrinter().withRootName("report").writeValueAsBytes(reports); } I tried to use: serialization inclusion: mapper

Jackson XML: how to serialize empty/null collections as empty node

不打扰是莪最后的温柔 提交于 2020-01-30 02:40:37
问题 I'm using Jackson XML 2.8.9 and unfortunately I cannot find any way to serialize empty/null collections as empty nodes. Method responsible for serializing to XML: protected byte[] toXml(final Collection<ReportView> reports) throws IOException { final XmlMapper mapper = new XmlMapper(); // place for code which will solve my problem return mapper.writerWithDefaultPrettyPrinter().withRootName("report").writeValueAsBytes(reports); } I tried to use: serialization inclusion: mapper