Java XML Binding [closed]

If you want to make an informed decision you need to be clear why you are translating between XML and java objects. The reason being that the different technologies in this space try to solve different problems. The different tools fall into two categories: XML data binding – refers to the process of representing the … Read more

JAXB, XJC -> create multiple class files

By default JAXB (JSR-222) will create static inner classes for nested complex types to prevent class name conflicts. You can use an external binding file to disable this behaviour. binding.xml A binding file allows you to customize how Java classes are generated from an XML schema. <jaxb:bindings xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:jaxb=”http://java.sun.com/xml/ns/jaxb” version=”2.1″> <jaxb:globalBindings localScoping=”toplevel”/> </jaxb:bindings> XJC Call … Read more

Where I can find a detailed comparison of Java XML frameworks? [closed]

As Blaise pointed out stick with the standards. But there are multiple standards created over the period to solve different problems/usecases. Which one to choose completely depends upon your requirement. I hope the below comparison can help you choose the right one. Now there are two things you have to choose. API and the implementations … Read more

Marshalling LocalDate using JAXB

You will have to create an XmlAdapter like this: public class LocalDateAdapter extends XmlAdapter<String, LocalDate> { public LocalDate unmarshal(String v) throws Exception { return LocalDate.parse(v); } public String marshal(LocalDate v) throws Exception { return v.toString(); } } And annotate your field using @XmlJavaTypeAdapter(value = LocalDateAdapter.class) See also javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters if you want to define your adapters … Read more

How to serialize and de-serialize objects using JAXB?

It would be nice if you included some code that explains your problem. JAXB 101 says you should place the right annotations, then you can serialize and deserialize correctly. You should properly annotate your classes with @XmlRootElement, @XmlElement, @XmlAttribute, etc For example: @XmlRootElement(name=”student”) @XmlAccessorType(XmlAccessType.NONE) class Student { @XmlElement(name=”name”) private String name; @XmlElement(name=”age”) private int age; … Read more

How do I prevent JAXBElement from being generated in a CXF Web Service client?

You have to create a binding file as below, this will get applied globally and use it as wsdl2java – b “bindings.txt” “wsdl” <jaxb:bindings version=”2.1″ xmlns:jaxb=”http://java.sun.com/xml/ns/jaxb” xmlns:xjc=”http://java.sun.com/xml/ns/jaxb/xjc” xmlns:xs=”http://www.w3.org/2001/XMLSchema”> <jaxb:globalBindings generateElementProperty=”false”/> </jaxb:bindings>