You should not use `readTree()` on XML data: it is supported only in a limited way. You should not use it. Behavior is such that if repeated elements are encountered only last is included, rest are ignored.
-+ Tatu +- On Thu, Nov 16, 2017 at 2:40 AM, Surinaidu Majji <[email protected]> wrote: > We are using Jackson libraries(2.8.3) in our project to read the xml file > and convert into json. > > When we read the data using the below code, the parser in the Jackson is > removing the entries in the > nested xml(childs) nodes except the last one node while converting from xml > data to json. > > The below is our code and input xml file data: > > > > XmlFactory factory = new XmlFactory(); > > JacksonXmlModule jm = new JacksonXmlModule(); > jm.setDefaultUseWrapper(true); > XmlMapper xmlMapper = new XmlMapper(jm); > > JsonParser parser = factory.createParser(new InputStreamReader(new > FileInputStream("bevarages.xml"), "UTF-8")); > TreeNode treeNode = xmlMapper.readTree(parser); > System.out.println(treeNode); > > > Xml data in the file:(bevarages.xml) > ====================== > > <?xml version="1.0" encoding="UTF-8" standalone="no"?> > <itemList> > <LIST> > <e> > <item> > <name>biscut</name> > <type>eatable</type> > </item> > </e> > <e> > <item> > <name/> > <type>drink</type> > </item> > </e> > </LIST> > </itemList> > > output produced from the above program is: > ========================================= > > {"LIST":{"e":{"item":{"name":null,"type":"drink"}}}} > > In the above program, the last item from the node itemList is taken and > ignored the first node. > > We have done some configuration(setDefaultUseWrapper(true)) using jackson > module to handle the inline xml nodes or arrays properly but no result. > > > Could any body have any idea, why Jackson parser behaves in this way. Is > there any configuration needs to given to handle the nested nodes. > > > > -- > You received this message because you are subscribed to the Google Groups > "jackson-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
