我读了很多关于如何在payara 5上将jackson替换为moxy但从未实现过一个好的解决方案,所以我创建了一个小项目,希望有人可以帮助我。
pom.xml
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>${version.javaee}</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<type>pom</type>
<version>1.4</version>
</dependency>
<dependencies>
Run Code Online (Sandbox Code Playgroud)
应用程序.java
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import org.glassfish.jersey.jackson.JacksonFeature;
@ApplicationPath("/api")
public class App extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
resources.add(JacksonFeature.class);
resources.add(SimpleService.class);
return resources;
}
}
Run Code Online (Sandbox Code Playgroud)
简单服务.java
@Path("sample")
public class SimpleService {
@Path("greet2")
@GET
@Produces(MediaType.APPLICATION_JSON)
public PojoEntity doGreet2() {
PojoEntity pojoEntity = new PojoEntity();
pojoEntity.setTeste1("TesteValue1");
pojoEntity.setTeste2("TesteValue2");
return pojoEntity;
}
}
Run Code Online (Sandbox Code Playgroud)
PojoEntity.java …