我有一个RESTful应用程序与球衣2(2.13)和glashfish4。
我的休息服务有效,但是我想在pojo / json json / pojo转换中使用特殊配置作为@JsonIngnore注释来避免循环引用(我也使用hibernate)。
我为我的杰克逊功能进行了自定义配置,但我认为这没有效果。我读到玻璃鱼上的球衣使用Moxy来默认。
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>