在将 Moxy Json 功能从 Jackson 功能配置到 Springboot + Jersey 应用程序时遇到问题。
所做的更改 -
在 ResourceConfig 扩展类中 -
//register(JacksonJsonProvider.class); #Commented
register(MoxyJsonFeature.class);
在 Pom.xml 文件中添加了以下内容 -
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.23.2</version>
</dependency>
API
@Produces(MediaType.APPLICATION_JSON)
@Path("/")
@Api(value = "xyz")
public class XyzController {
@GET
@Path(Urls.XYZ)
@ApiOperation(value = "xyz", notes = "xyz", nickname = "xyz")
public Long xyz(@Valid @BeanParam final FetchParams fetchParams) {
return testService.xyz(fetchParams);
}
}
api面临的异常 -
Caused by: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class java.lang.Long, genericType=class java.lang.Long.
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:247)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86)