Thursday, 15 January 2015

java ee - Jersey2 + JacksonFeature issues on Glashfish 4 -



java ee - Jersey2 + JacksonFeature issues on Glashfish 4 -

i have restful aplication bailiwick of jersey 2 (2.13) , glashfish4.

my rest services works, want utilize special configuration in pojo/json json/pojo conversion @jsoningnore annotation avoid circular references (i'm using hibernate too).

i create custom configuration jackson feature think not have effect. read bailiwick of jersey on glassfish utilize moxy default.

app.java

@javax.ws.rs.applicationpath("resources") public class app extends resourceconfig { public app() { register( jacksonfeature.class ); packages("com.gere.webservices"); }

jacksonfeature.java

public class jacksonfeature implements feature { private static final objectmapper mapper = new objectmapper(){{ configure(serializationfeature.indent_output, true); configure(deserializationfeature.accept_empty_string_as_null_object, true); configure(deserializationfeature.fail_on_unknown_properties, false); configure(serializationfeature.fail_on_empty_beans, false); }}; private static final jacksonjaxbjsonprovider provider = new jacksonjaxbjsonprovider(){{ setmapper(mapper); }}; @override public boolean configure(featurecontext context) { string postfix = '.' + context.getconfiguration().getruntimetype().name().tolowercase(); context.property( commonproperties.moxy_json_feature_disable + postfix, true ); context.register(provider); homecoming true; } }

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>servlet 3.0 web application</display-name> <servlet> <servlet-name>jersey2 akka rest servlet</servlet-name> <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class> <init-param> <param-name>javax.ws.rs.application</param-name> <param-value>com.gere.app</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>jersey2 akka rest servlet</servlet-name> <url-pattern>/data/*</url-pattern> </servlet-mapping> </web-app>

pom.xml

<dependency> <groupid>org.glassfish.jersey.core</groupid> <artifactid>jersey-server</artifactid> <version>${jersey.version}</version> <exclusions> <exclusion> <groupid>com.google.guava</groupid> <artifactid>guava</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>org.glassfish.jersey.containers</groupid> <artifactid>jersey-container-servlet</artifactid> <version>${jersey.version}</version> </dependency> <dependency> <groupid>org.glassfish</groupid> <artifactid>javax.json</artifactid> <version>1.0.4</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.jaxrs</groupid> <artifactid>jackson-jaxrs-json-provider</artifactid> <version>2.4.3</version> </dependency>

java-ee jackson jax-rs glassfish-4 jersey-2.0

No comments:

Post a Comment