Using jackson in tomee as JAXB-Json provider

Jackson is fast JSON processor with nice default behavior, e.g. single element collections are represented as JSON arrays, and there are no wrapping elements.

Because the default is already reasonable, there is no additional configuration needed. The provider can be specified directly in the /src/main/webapp/WEB-INF/openejb-jar.xml descriptor:

<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 = com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
        </properties>
    </pojo-deployment>
</openejb-jar>

In addition the jackson dependency needs to be declared in the pom.xml:

<dependency>
	<groupId>com.fasterxml.jackson.jaxrs</groupId>
	<artifactId>jackson-jaxrs-json-provider</artifactId>
	<version>2.4.3</version>
</dependency>

A better solution would be to install jackson directly on the server (/apache-tomee-plus-1.7.1/lib), what would keep your WAR skinny.

via: http://www.adam-bien.com/roller/abien/entry/using_jackson_in_tomee_as

Json Rest Client to beans with Jodd-http and Jackson


package gob.documental.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import gob.documental.DocsVars;
import gob.documental.web.acl.UserDataJson;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;

/**
 *
 * @author Fernando
 */
public class AclServiceWs implements AclService{
    
    @Override
    public UserDataJson login(String user, String pass){
        
        UserDataJson userData = new UserDataJson();
        
        String urlRest = DocsVars.sgmUrl + "rest/acceso/auth/userName/"+user+"/password/"+pass+"/get";
        Logger.getLogger(AclServiceWs.class.getName()).log(Level.INFO, "URL: {0}", urlRest);
        
        HttpRequest httpRequest = HttpRequest.get(urlRest);
        HttpResponse response = httpRequest.send();
        
        ObjectMapper mapper = new ObjectMapper();
        String bodyResp = response.bodyText();
        
        try {
            Logger.getLogger(AclServiceWs.class.getName()).log(Level.INFO, bodyResp);
            userData =  mapper.readValue(bodyResp, UserDataJson.class);
        } catch (IOException ex) {
            Logger.getLogger(AclServiceWs.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        // comprobar usuario existente:
        if(userData.getId()!=null){
            return userData;
        }
        
        return null;
    }
    
}

Using Jackson json parser in Apache Tomee 1.5 rest

Code in WEB-INF/openejb-jar.xml for every rest bean, in this case MobileRest:

    <pojo-deployment class-name="com.origami.catastro.mobile.rest.MobileRest">
        <properties>
            cxf.jaxrs.providers = jsonProvider, jaxbProvider
        </properties>
    </pojo-deployment>

Add services in WEB-INF/resources.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <Service class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" id="jsonProvider"/>
  <Service class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" id="jaxbProvider"/>
  <Resource id="smbcatas documental dev" type="javax.sql.DataSource">#Fri May 16 11:29:49 COT 2014
jdbcDriver=org.postgresql.Driver
password=asdfasdfasdf
userName=asdfasdfasdf
jdbcUrl=jdbc\:postgresql\://193.87.122.200\:5432/smbcatas
</Resource>
</resources>