JAXB has well established rules for converting Java names to XML names. If you want to override the default name you can always do so through the use of annotations. Where this can become burdensome is if your names follow common rules (such as make everything upper case). In the upcoming EclipseLink 2.3 release we have added a new MOXy JAXB feature that allows you to override the default naming algorithm. You can try this out today using a nightly download:
May 27, 2011
May 24, 2011
JAXB and DTD - Apache log4j Example
There is a common misconception that JAXB requires an XML Schema. This is understandable since JAXB offers the ability to derive Java classes from an XML schema, and generate XML schemas from annotated Java classes. In reality the JAXB annotations are used to map XML to objects, and although not part of the JAXB specification, the XJC tool offers the ability to generate Java classes from a DTD. In this post we will use JAXB to interact with XML that corresponds to the Apache log4j DTD.
May 13, 2011
JAXB and Interface Fronted Models
Usually with JAXB we are mapping POJOs to XML. In this example I will demonstrate how to handle a Java model that is exposed through a set of interfaces. This post was inspired by an answer I gave (feel free to upvote) to a question on Stack Overflow. In the question the poster was running into exceptions like the one below. This post will cover how to properly map this use case.
Exception in thread "main" com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 6 counts of IllegalAnnotationExceptions blog.interfaces.Customer is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at blog.interfaces.Customer blog.interfaces.Customer does not have a no-arg default constructor. this problem is related to the following location: at blog.interfaces.Customer ...
May 5, 2011
Schema to Java: @XmlMimeType & @XmlInlineBinaryData
In a previous post I described the impact of the @XmlInlineBinaryData and @XmlMimeType annotations in a JAX-WS environment where binary data may be sent as attachments. One of the comments I received on that post was how to have those annotations generated onto your classes when starting from an XML schema. In this post I will address that question.
Labels:
Bindings File,
JAXB,
XmlInlineBinaryData,
XmlMimeType
May 3, 2011
Specifying EclipseLink MOXy as Your JAXB Provider
To specify EclipseLink MOXy as the JAXB provider you need to put a jaxb.properties file in one of the packages for your domain classes, that is passed in to bootstrap the JAXBContext.
April 15, 2011
@XmlAnyElement and non-DOM Properties
This post will cover how to use an alternate DOM representation (i.e. String) with @XmlAnyElement.
JAXB and JSON via Jettison - Namespace Example
In a previous post I described how Jettison can be leveraged by a JAXB implementation to produce/consume JSON. A reader correctly pointed out that I did not describe how to handle namespaces. Since JSON does not support namespaces you would not normally include them in your mappings. However if you wanted to map your object model to both JSON and XML with namespaces, this post will demonstrate how it can be done.
XML Schema to Java - XSD Choice
In a previous blog post I wrote about how to map to the choice structure in XML schema when starting from classes. An astute reader tried generating an object model from that schema and noticed that the JAXB implementation generated something different than expected. In this post I'll explain the difference.
April 12, 2011
JAXB and JSON via Jettison
JAXB implementations (Metro, EclipseLink MOXy, Apache JaxMe, etc) provide an easy means of converting objects to/from XML. There is a library called Jettison that exposes access to JSON messages via the StAX API that a JAXB implementation can use to convert objects to/from JSON. This library is being leveraged by a number of JAX-RS implementations. In this post I'll demonstrate its use in a standalone example.
April 11, 2011
MOXy's XML Metadata in a JAX-RS Service
In previous posts I introduced how EclipseLink JAXB (MOXy) can represent it's metadata as XML, and how MOXy can be used in a JAX-RS service. In this post I'll demonstrate how to leverage MOXy's metadata file in a JAX-RS service by using a ContextResolver.
Labels:
EclipseLink,
Extension,
JAX-RS,
Mapping File,
MOXy,
REST
Subscribe to:
Posts (Atom)