Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-2016

JsonBindingProvider hides the root cause of "JSON Binding deserialization error"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 3.6.2.Final, 4.0.0.Beta6
    • None
    • None
    • None

      JsonBindingProvider logging needs to be reevaluated.

      Currently, readForm prints different exception details as write to. We need to unify logging of exceptions for server/client side and writeTo/readFrom use-cases.

      This is important for RESTEasy users. Better logging allows to better investigation of user's use-cases, see: https://developer.jboss.org/message/984944#984923

      In the past, logging was changed by https://github.com/resteasy/Resteasy/pull/1485/files


      Specific logging issue (this is probably usecase of https://developer.jboss.org/message/984944#984923):
      JsonBindingProvider hides the root cause of "JSON Binding deserialization error" on client side.

      Simple end-point with corrupted json data:

          @GET
          @Path("core/h")
          public Response h() {
              return Response.status(200).type(MediaType.APPLICATION_JSON_TYPE).entity("{\"a\":100,\"b").build();
          }
      

      Client code:

      WebTarget target = client.target("http://localhost:8080/jaxrs-wf/a/core/h");
      Response r = target.request().get();
      Map t = r.readEntity(new GenericType<Map<String, Integer>>() {
      });
      System.out.println(t);
      

      Client prints this exception:

      Exception in thread "main" javax.ws.rs.ProcessingException: RESTEASY008200: JSON Binding deserialization error
      	at org.jboss.resteasy.plugins.providers.jsonb.JsonBindingProvider.readFrom(JsonBindingProvider.java:88)
      	at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:66)
      	at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:56)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:334)
      	at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:261)
      	at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:245)
      	at com.resteasy.test.App.main(App.java:52)
      

      This exception doesn't print "what is wrong". Debug messages doesn't help as well. This can be fixed by this:

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      diff --git a/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/JsonBindingProvider.java b/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/JsonBindingProvider.java
      index 8ad7a6a91..61e3c9ba3 100644
      --- a/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/JsonBindingProvider.java
      +++ b/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/JsonBindingProvider.java
      @@ -84,7 +84,7 @@ public class JsonBindingProvider extends AbstractJsonBindingProvider
                   return null;
                }
                // detail text provided in logger message
      -         throw new ProcessingException(Messages.MESSAGES.jsonBDeserializationError(e));
      +         throw new ProcessingException(Messages.MESSAGES.jsonBDeserializationError(e, e.getMessage()));
             }
          }
          
      diff --git a/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/i18n/Messages.java b/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/i18n/Messages.java
      index 25d325aaf..c6bebbc00 100644
      --- a/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/i18n/Messages.java
      +++ b/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/i18n/Messages.java
      @@ -13,8 +13,8 @@ public interface Messages
          Messages MESSAGES = org.jboss.logging.Messages.getBundle(Messages.class);
          int BASE = 8200;
       
      -   @Message(id = BASE + 00, value = "JSON Binding deserialization error", format=Format.MESSAGE_FORMAT)
      -   String jsonBDeserializationError(@Cause Throwable element);
      +   @Message(id = BASE + 00, value = "JSON Binding deserialization error: {0}", format=Format.MESSAGE_FORMAT)
      +   String jsonBDeserializationError(@Cause Throwable element, String rootCauseMsg);
       
          @Message(id = BASE + 05, value = "JSON Binding serialization error {0}", format=Format.MESSAGE_FORMAT)
          String jsonBSerializationError(String element);
      

      ->

      Exception in thread "main" javax.ws.rs.ProcessingException: RESTEASY008200: JSON Binding deserialization error: Unexpected char -1 at (line no=1, column no=21, offset=20)
      	at org.jboss.resteasy.plugins.providers.jsonb.JsonBindingProvider.readFrom(JsonBindingProvider.java:87)
      	at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:66)
      ...
      

      But we need to have complex fix for all use-cases (server/client side and writeTo/readFrom use-cases).

              rsearls r searls
              mkopecky@redhat.com Marek Kopecky
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: