私はjsonから直接にマップしようとしています。 GETリクエストの場合、これはスムーズに動作しています。 POST要求の場合、例外が発生します。ジャーナル2.xはjsonの入力パラメーターでスローします。MessageBodyProviderNotFoundException
リソースメソッド:
@GET
@Path("testget")
@Produces(MediaType.APPLICATION_JSON)
public Response test(@Context HttpServletRequest request) {
Password password = new Password();
password.setPassword("testpassword");
return Response.status(Response.Status.OK).entity(password).build();
}
@POST
@Path("testpost")
@Consumes(MediaType.APPLICATION_JSON)
public Response test(Password password) {
return Response.status(Response.Status.OK).entity(password.getPassword()).build();
}
クライアント:
Response reponse = target.request(MediaType.APPLICATION_JSON).get();
Password password = new Password();
password.setPassword("newTestPasswort");
reponse = target.request(MediaType.APPLICATION_JSON).post(Entity.json(password));
例外:
SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.entities.Password, genericType=class com.entities.Password.
Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class com.entities.Password, genericType=class com.entities.Password.
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.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:502)
at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:388)
at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
at com.clientsql.RegistrationTest.setNewPassword(RegistrationTest.java:61)
at com.clientsql.RegistrationTest.main(RegistrationTest.java:44)
依存関係:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.23.1</version>
</dependency>
マッピングのために私はさまざまな依存関係を試しました。それぞれの場合、get関数のみが動作します。
<dependency>
<groupId>com.owlike</groupId>
<artifactId>genson</artifactId>
<version>1.4</version>
</dependency>
<!-- <dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.23.1</version>
</dependency>-->
<!-- <dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.23.1</version>
</dependency>-->
://owlike.github.io/genson/Documentation/Extensions/#jax-rs-jersey--cie)。 – eugen