Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Implementing XMLNameTransformer breaks JSON mapping of abstract classes
Implementing XMLNameTransformer breaks JSON mapping of abstract classes [message #1111836] Wed, 18 September 2013 20:09 Go to next message
Andy Chillrud is currently offline Andy ChillrudFriend
Messages: 1
Registered: September 2013
Junior Member
I'm using Jersey 2.2 with EclipseLink 2.5.0 to implement a REST API on top of a third party SDK. I have implemented my own representation wrapper around one of the 3rd party classes, and am using JAXB annotations in my wrapper class to generate JSON and XML.

I have implemented GET and POST operations which produce and consume either JSON or XML. This is working correctly, however the JSON fieldnames/XML element names for the wrapped 3rd party class are camel case (fieldId) and I have a requirement that they be snake case (field_id).

I created a XMLNameTransformerXML implementation that transforms element names, and implemented a XML mapping file for the 3rd party package, which is loaded by an implementation of ContextResolver<JAXBContext>. All the XML mapping file really does is reference my XMLNameTransformerXML implementation.

This seemed to work, and the field/elements names generated for the 3rd party class when I perform a GET are now displayed in snake case. However the POST operation is only successful with XML. When I pass it JSON I get an exception:
http-0.0.0.0-11090-1 2013-09-18 14:58:17,031 | ERROR | session=       | user=           | org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/example].[Jersey Web Application] | Servlet.service() for servlet Jersey Web Application threw exception
Local Exception Stack:

Exception [EclipseLink-43] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value [example.jersey.representations.ConcreteExampleA] of type [class java.lang.String].
Descriptor: XMLDescriptor(example.jersey.representations.AbstractExample --> [])


The 3rd party class contains several members that are defined as Lists of abstract objects. This is where the problem seems to lie. Looking at the source code for the 3rd party library, each of the abstract base classes has a @XmlSeeAlso annotation that lists the concrete derived classes.

I implemented a test case that doesn't use the 3rd party (see attached zip file), and am able to reproduce the problem.

Any suggestions?

Thanks, Andy
Re: Implementing XMLNameTransformer breaks JSON mapping of abstract classes [message #1112525 is a reply to message #1111836] Thu, 19 September 2013 20:54 Go to previous message
Denise Smith is currently offline Denise SmithFriend
Messages: 11
Registered: July 2009
Junior Member
Hi

I've entered a bug for this issue
https://bugs.eclipse.org/bugs/show_bug.cgi?id=417644

A possible workaround would be to set the following property to something that will never be in your JSON doc as an indicator for inheritance ie:
unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR, '#');

By default the namespace separator is a dot '.' and since your indicator values ie: example.jersey.representations.ConcreteExampleA contain dots we are incorrectly handling that value.

Another workaround would be if you alter your Nametransformer to not have dots in the returned names you shouldn't hit this issue either.
Previous Topic:Bidirectional one-to-one relations with dynamic entities
Next Topic:JAXB / MOXy - not unmarshalling values after ignored elements
Goto Forum:
  


Current Time: Thu Apr 25 10:21:14 GMT 2024

Powered by FUDForum. Page generated in 0.02897 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top