This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes BEA/Weblogic and the fly likes WebLogic: let MOXy throw a JAXBException for invalid JSON requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "WebLogic: let MOXy throw a JAXBException for invalid JSON requests" Watch "WebLogic: let MOXy throw a JAXBException for invalid JSON requests" New topic

WebLogic: let MOXy throw a JAXBException for invalid JSON requests

Rob Isaacs

Joined: Mar 12, 2014
Posts: 20
We're using WebLogic (12c), and are working on a REST application with JSON for requests and responses. If the requests are valid everything works just fine. However, when a request is not correctly formatted, we expect an exception (which we can map to the right responses, if necessary). Instead, the value remains null instead. (Of course we can then validate that the value is not null, but what if null is allowed for some fields? We won't be able to see the difference between absent fields and incorrectly formatted fields, so instead of rejecting the request we would accept it as if no value was sent.)

We have created a subclass of annotated with @Provider which sets some custom properties, but even without this (so with the default JSON handling) no exceptions are thrown.

We have already traced this internally to org.eclipse.persistence.oxm.record.UnmarshalRecord which treats each org.eclipse.persistence.exceptions.EclipseLinkException as warnings, meaning that (by default) they are ignored. The actual EclipseLinkException thrown is a org.eclipse.persistence.exceptions.ConversionException wrapped around the actual exception thrown by the XmlAdapter. This ConversionException is thrown from org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter's convertDataValueToObjectValue.

We can already work around this ConversionException being ignored, but we still get a ConversionException instead of a JAXBException. This means we cannot show to the caller which field is invalid; all we have is "The object [XXX], of class [class java.lang.String], could not be converted to [class YYY]". Since class YYY may be used in more than 1 request we cannot assume the same mapping. The exception stack trace can also not be used since it doesn't even enter the REST method.

Is there a way to get, instead of the ConversionException, a JAXBException (preferably a PropertyException)?
I agree. Here's the link:
subject: WebLogic: let MOXy throw a JAXBException for invalid JSON requests
Similar Threads
Just Finished in OCEWCD Learning
Unable save multi select box value into database using Grails and groovy
Input Validation
cannot resolve symbol error occuring for a method...
Get rid of line numbers