java 变得严重:找不到媒体类型=application/json、类型=class org.json的消息正文编写器,JSON对象

h22fl7wq  于 2023-02-28  发布在  Java
关注(0)|答案(1)|浏览(170)

I am just writing a client method and invoking the POST method. But i am facing the below error.
When i test the webservices url though postman its working. Only in my client code its giving error.
Mar 29, 2016 5:39:27 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo SEVERE: MessageBodyWriter not found for media type=application/json, type=class org.json.JSONObject, genericType=class org.json.JSONObject. Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class org.json.JSONObject, genericType=class org.json.JSONObject. 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.doWriteEntity(ClientRequest.java:517) at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:499) 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$2.call(JerseyInvocation.java:700) 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:696) at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448) at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349) at test.restful.webservices.TESTClient.testUpdateUser(TESTClient.java:58) at test.restful.webservices.TESTClient.main(TESTClient.java:89)
Here is my Code:

private void testUpdateUser(){
      FormBean sample = new FormBean();  
      sample.setFORM_LONG_DESC("FrmIssCMNEW");       
      JSONObject jo = new JSONObject(sample);
      System.out.println("Json ===>>"+jo);
      String callResult = client
          .target(REST_SERVICE_URL)
          .path("/Add")
          .queryParam("formcode", "FrmIssCMNEW")
          .queryParam("dsnID","OFSBGRC")
          .queryParam("version","1")
          .queryParam("longdesc","testing by me")
         .request(MediaType.TEXT_PLAIN)
         .post(Entity.entity(jo,MediaType.APPLICATION_JSON),
            String.class);

  Post Method:
  @POST
  @Produces(MediaType.TEXT_PLAIN)   
  @Path("/Add")
  public String save
  (     @QueryParam("formcode") String formcode,
        @QueryParam("version") int version,
        @QueryParam("dsnID") String dsnID,
        @QueryParam("longdesc") String longdesc)
    {   
       /* my code */
           return "Display from POST method  <> "+"FormID :"+fb.getFORM_ID()+" -->> FormLong Description :"+fb.getFORM_LONG_DESC();

   }

Thanks In Advance.

mqkwyuun

mqkwyuun1#

我也遇到了类似org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=class java.util.ArrayList的错误
我这里的编码

Response response = builder.post(Entity.entity(userIdList, "application/json"));

找不到解决办法

相关问题