Java 如何在payara 5上替换moxy的jackson
我读了很多关于如何在payara 5上用moxy替换jackson的文章,但从来没有找到一个好的解决方案,所以我创建了一个小项目,希望有人能帮助我 pom.xml PojoEntity.java 将此微型应用程序部署到payara 5并请求端点后,结果是(如预期的那样): Payara正在使用Jackson而不是moxy.:)很好 ============================================== 我的问题是当我使用microfile到达自己的端点时: SimpleServiceFileAPI.java MicroService.java 并在getClasses方法的App.java上添加以下行:Java 如何在payara 5上替换moxy的jackson,java,jackson,moxy,payara,microprofile,Java,Jackson,Moxy,Payara,Microprofile,我读了很多关于如何在payara 5上用moxy替换jackson的文章,但从来没有找到一个好的解决方案,所以我创建了一个小项目,希望有人能帮助我 pom.xml PojoEntity.java 将此微型应用程序部署到payara 5并请求端点后,结果是(如预期的那样): Payara正在使用Jackson而不是moxy.:)很好 ============================================== 我的问题是当我使用microfile到达自己的端点时: SimpleSe
resources.add(MicroService.class);
通过此修改重新部署后,我们可以访问,结果是:
{"teste1":"LOL","differentName":null}
显然,这个文件一直在使用moxy并忽略PojoEntity属性“differentName”
有人知道在这个例子中完全取代moxy的方法吗
此项目可用于测试这种情况。:)
帕亚拉版本:5.183
提前感谢。您只需在SimpleServiceMicrofileAPI上注册JacksonFeature:
@RegisterProvider(JacksonFeature.class)
这应该会让它起作用;)
public class PojoEntity {
private String teste1;
@JsonProperty("differentName")
private String teste2;
//getters and setters
}
{"teste1":"TesteValue1","differentName":"TesteValue2"}
import javax.enterprise.context.Dependent;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@Dependent
@RegisterRestClient
@Produces(MediaType.APPLICATION_JSON)
public interface SimpleServiceMicroprofileApi {
@Path("api/sample/greet2")
@GET
@Produces(MediaType.APPLICATION_JSON)
public PojoEntity recallGreet2();
}
package fish.payara.micro.sample;
import java.net.MalformedURLException;
import java.net.URL;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
@Path("micro")
public class MicroService {
@Path("recallGreet2")
@GET
@Produces(MediaType.APPLICATION_JSON)
public PojoEntity recallGreet2() throws MalformedURLException {
PojoEntity pojoEntity = new PojoEntity();
pojoEntity.setTeste1("LOL");
pojoEntity.setTeste2("LOL2");
URL apiUrl = new URL("http://localhost:8080/micro-sample");
SimpleServiceMicroprofileApi playlistSvc = RestClientBuilder.newBuilder().baseUrl(apiUrl)
.build(SimpleServiceMicroprofileApi.class);
return playlistSvc.recallGreet2();
}
}
resources.add(MicroService.class);
{"teste1":"LOL","differentName":null}
@RegisterProvider(JacksonFeature.class)