Jackson JSON User Group

JSON in Java the Right Way -- Action, Jackson!

"Unrecognized field (..), not marked as ignorable" while jaxb unmarshalling xml input

[To begin with: I already tried stackoverflow without getting any suggestions]

 

Hi there,

 

in a typical Spring MVC project, I am trying to access objects that are fetched from an external webservice source. The actual integration of this data wasn't actually - until now - my part within the project. But it's broke and I'll have to fix it. That is to say: I am not perfectly familar with the related code.

 

The Issue

The problem is, that I am not able to deserialize some of the classes, that are provided by the webservice using XML or Json. In fact, I think those are malfunctioning, which embed Lists of objects. However, the annotations of my classes look fine to me: In fact, these are exactly the annotation used within the external web service to create the xml/json documents (using jersey). 

 

The Exception:

  1. Fetching the objects as XML: http://pastebin.com/nAugj1sw
  2. Fetching the objects as Json: http://pastebin.com/zypRv0SJ

The Backgrounds

The Data

The Mapping Annotations / The Classes

The Configuration

The fetching method:

--

 

So, the xml/json input documents look pretty fine to me. The above mentioned method works for "simple" objects, but not for these with embedded Lists of Objects (like OfferedServicesTO.class). Since this whole mapping/unmarshalling process is kind of a black box to me, I am out of ideas how to get this issue solved (either using the json feed or the xml feed) .

 

I would appreciate any suggestions. Thank you.

-- Martin

 

Tags: jaxb, json, spring, unmarshalling, xml

Views: 3822

Reply to This

Replies to This Discussion

Looking at the first JSON-related exception, it says that Jackson can't really instantiate object of type "javax.xml.transform.Source", which is true -- it has no idea what that is. To solve this, you'd need to find a way to unwrap this somehow; this is an XML/XSLT abstraction so Jackson can't do much about it.

As to missing "service"; it could be some naming issue (excepted property name is something other than 'service'; JSON input has 'service' but logical property name, say, "services" or something). Or there just might not be a setter or field to set value to. This could also be due to type information missing; if something is declared as "List<Object>", there is no way to know types without embedding type information.

If type information is needed, Jackson has couple of ways to allow this: one is to add @JsonTypeInfo on the base class. But this wouldn't work for java.lang.Object; there are other ways to do this, but that's more complicated subject.

For types like 'List<Object>', you could also indicate actual content type by something like:

   @JsonDeserialize(contentAs=ActualValue.class) public List<Object> values;

I hope these help get started; other than this, I think you need to be able to isolate problems further. It is tricky to trouble-shoot complex set ups.

 

Okay, this was easier than expected. The List field needs a wrapping layer. A closer look to the json document (this was my first mistake: the missing 'service' field exception related top the json feed, not to the xml feed) revealed the solution:


In OfferedServiceTO.class the


@XmlElementWrapper(name="services")
@XmlElement(name="service")
public List services;


has to be changed to


@XmlElement(name="services")
public ServiceTOList services;

where ServiceTOList.class has to be something like:



@XmlRootElement(name="service")
public class ServiceTOList extends ArrayList {
public List services;
}

Thank you for your explanatory notes.

-- Martin

Ok good. Glad you got it working.

RSS

© 2014   Created by Tatu Saloranta.   Powered by

Badges  |  Report an Issue  |  Terms of Service