Configuring The JSON Default Provider (jettison) in TomEE

TomEE comes with Jettison and cxf as standard JAXB and JAX-RS providers. Jettison is "chatty" and might require some tweaking.

To tweak Jettison in a WAR deployment, you will have to provide two configuration files:

The first src/main/webapp/WEB-INF/resources.xml configures the JSON provider:


<?xml version="1.0"?>
<resources>
    <Service id="jsonProvider" class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
        dropRootElement=true
        supportUnwrapped = true
        dropCollectionWrapperElement=true
    </Service>
</resources>

In the /src/main/webapp/WEB-INF/openejb-jar.xml descriptor, you only have to refer to the earlier defined configuration:


<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.openejb.org/openejb-jar/1.1">
    <pojo-deployment  class-name="jaxrs-application">
        <properties>
            cxf.jaxrs.providers = jsonProvider
        </properties>
    </pojo-deployment>
</openejb-jar>

TomEE greatly simplifies the configuration--checkout the CXF standalone example as reference / comparison.

See you at Java EE Workshops at Munich Airport, Terminal 2 or on demand and in a location very near you: airhacks.io!

Comments:

Just tested on 1.7.1, using dropCollectionWrapperElement=true would give you invalid JSON format. It seems like you need serializeAsArray=true as well.

Posted by Non-Non on November 12, 2014 at 05:58 AM CET #

Hello,

I've been have this problem for quite a while. I couldn't find on the internet another way to solve it. Your well detailed post was the only place that could save my problem. Many thanks! =****

Posted by Pedro on March 19, 2015 at 05:29 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License