users@jersey.java.net

[Jersey] Parsing JSON with _at_-marked attributes

From: feldberg ian <ianfeldberg_at_yahoo.com>
Date: Wed, 2 Oct 2013 07:44:06 -0700 (PDT)

Hi. I'm using Jersey 1.x to serve up some JAXB-annotated Java objects through a REST endpoint. When I request these objects in JSON format (application/json) they correctly get served, that is, fields in the object annotated as @XmlAttribute's have an at sign prepended to their name. Then when I PUT or POST those strings back to the REST endpoint, they get correctly parsed as attributes and not XML elements. Good Jersey.

Now, I need to be able to parse JSON strings into JAXB Java objects without the REST endpoint. I will be getting the strings directly from JavaScript. I've read conflicting information about which JSON Provider (MOXy, Jackson, Jettison) Jersey uses so I started with Jackson. I created an ObjectMapper and even set the AnnotationIntrospector to only use JAXB but I still get the exception:

    org.codehaus.jackson.map.exc.UnrecognizedPropertyException:Unrecognizedfield "@Graphic" not marked as ignorable

Well I'm not going to mark it as ignorable because I don't want it ignored! I want it interpreted as an XML attribute! I thought about not setting the @ in the first place but these JAXB classes get generated from an XML schema controlled by another group so I can't exactly change the schema to not have attributes.

Is there a flag in Jackson that will allow me to parse strings that start with an "@" as attributes? Am I barking up the wrong tree? Maybe Jersey 1.x doesn't use Jackson as I was told...