Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
The JAXB (JSR-222) specification does not cover JSON binding. When JAXB annotated models are used with JAX-RS implementations there is processing beyond the JAXB spec that is occuring. This is why when you try to use the standard JAXB APIs to process the JSON message you get an XML parser exception.
Demo
EclipseLink MOXy is a JAXB implementation that offers native support for JSON-binding (see: http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html). Below is an example using your domain model as posted in your question (with accessors added)
package forum13652303;
import java.io.File;
import java.util.*;
import javax.xml.bind.*;
import org.eclipse.persistence.jaxb.JAXBContextProperties;
public class Demo {
public static void main(String[] args) throws Exception {
Map<String, Object> properties = new HashMap<String, Object>(1);
properties.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
JAXBContext jc = JAXBContext.newInstance(new Class[] {Customer.class}, properties);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File json = new File("src/forum13652303/input.json");
Customer customer = (Customer) unmarshaller.unmarshal(json);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(customer, System.out);
}
}
jaxb.properties
To use MOXy as your JAXB provider you need to add a file called jaxb.properties
in the same package as your domain model with the following entry (see: http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html):
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
input.json/Output
{
"customer" : {
"city" : "city1 ",
"companyName" : "companyName1 ",
"custNo" : "RCN1",
"email" : "email1@ge.com",
"firstName" : "first1 ",
"gender" : "F",
"lastName" : "last1 ",
"midInit" : "K",
"phone" : "4082229871 ",
"state" : "CA",
"streetAddress" : "streetAddress1",
"title" : "S ",
"zipCode" : "zipCode "
}
}