Handling of JAXB @XMLElements in Jackson

520 views
Skip to first unread message

Pawan Gandhi

unread,
May 9, 2014, 11:16:20 AM5/9/14
to jackso...@googlegroups.com
Hi All,

I am a bit new to Jackson and as of now struggling with deserializing a particular JSON request of the following format

{"SearchCriteria":{"SearchOperationList":[{"Name":"Products","Value": "Adalimumamb","Operator": "="}],"SearchEquation": [{"Name": "Products","Value":"Adalimumamb","Operator":"="}]}}

The SearchCriteria Java Class contains the following JAXB Annotation:

@XmlRootElement(name = "SearchCriteria")
public class SearchCriteriaType {

protected Object[] searchClause;

@XmlElements({@XmlElement(name = "SearchOperationList", type = SearchOperationType.class), @XmlElement(name = "SearchEquation", type = SearchAttributeType.class)})
public Object[] getSearchClause() {
return searchClause;
}

public void setSearchClause(Object[] searchClause) {
this.searchClause = searchClause;
}

}

The target of this implementation is to store both JSON Array Objects coming from "SearchOperationList" and "SearchEquation" into the same Object[] array

I get the following exception while the request is being processed.

Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "SearchEquation" (Class SearchCriteriaType), not marked as ignorable

All this implementation is part of REST-full webservice using Apache CXF framework and JsonProvider being used is 
org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider

Jackson version is 1.9

Any help on how to achieve this would be appreciated.

TIA
Pawan

Tatu Saloranta

unread,
May 9, 2014, 2:16:36 PM5/9/14
to jackso...@googlegroups.com
I don't think that approach will work: you are trying to do a complex transformation of a structure that does not match objects.

Why not design objects that actual match data here? You can transform data later on, but trying to figure out structural annotations by annotations gets complex very quickly.
If you instead just bound two lists into two distinct properties, it would be straight-forward and work reliably.

Or, use a Map<String, Object> to map any number of variations.

-+ Tatu +-
 
TIA
Pawan

--
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 jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pawan Gandhi

unread,
May 13, 2014, 2:49:11 AM5/13/14
to jackso...@googlegroups.com
Thanks Tatu for the confirmation. I will look for alternatives
Reply all
Reply to author
Forward
0 new messages