0

I have a RESTful aplication with jersey 2 (2.13) and glashfish4.

My rest services works, but I want use special configuration in the pojo/json json/pojo conversion as @JsonIngnore annotation to avoid circular references (I'm using hibernate too).

I make a custom configuration for my jackson feature but I think this not have effect. I read that jersey on glassfish use Moxy to 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);
        return 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>
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Gere
  • 2,114
  • 24
  • 24
  • I couldn't reproduce the problem. If what you were trying to do was get rid of say a "One" side in a "Many" object, I was was not able to reproduce the problem (using @JsonIgnore on the "One" property in the "Many" class). Only difference was I use `Application` instead of `ResourceConfig`. Shouldn't be a problem though. – Paul Samsotha Nov 04 '14 at 08:04
  • You can do it also easily without an dependencies, using `@XmlTransient`. – Paul Samsotha Nov 04 '14 at 08:08

0 Answers0