Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB or Jackson for xml unmarshalling?

Receiving an XML response, there are two main solutions decoding xml to a DTO object. Why should one prefer JAXB over jackson, or the other way around?

JAXB:

Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlString));
unmarshaller.unmarshal(reader, DtoObject.class);

Jackson:

mapper = new ObjectMapper() / new XmlMapper();
mapper.readValue(xmlString, DtoObjectc.class);
like image 713
membersound Avatar asked Nov 18 '25 14:11

membersound


1 Answers

In my opinion, I will use JAXB, the following reason.

  1. It is quite matured and part of JDK.
  2. I do not need third party additional library to use
  3. Jackson2 XML transformation is new as compared to JAXB which is in the industry for a quite long time and there are lot of community for it.

However I am not saying that which is good or bad. Again it is a choice to the developer to use.

like image 198
Sambit Avatar answered Nov 21 '25 05:11

Sambit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!