5
我決定搬到Jersey 2.5
,我在Java Beans
轉換爲JSON
時遇到了一些問題。我有一個User
Bean,並且我試圖返回一個服務列表users
。從Jersey 1. *升級到Jersey 2.5
其獲取用戶的列表我的服務代碼:
@GET
@Path("getAllUsers")
@Produces(MediaType.APPLICATION_JSON)
public List<User> getAllUsers() {
//Fetching users list here
return users;
}
我獲得以下服務器控制檯的例外:
[org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<com.example.User>.] with root cause
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<com.example.User>.
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:227)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:103)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:88)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1139)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:574)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:381)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:371)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:262)
我缺少的任何相關性或任何特定的2.5配置?
沒有。你使用哪個JSON提供者?你在GF4上運行還是在使用其他容器? –
@MichalGajdos Jackson和Tomcat。 –
謝謝,請說清楚。您依賴於'jersey-media-json-jackson'或直接在Jackson 2.x上,而不是其他JSON提供者(即'jersey-media-moxy')。我對嗎? –