Uploaded image for project: 'Errai'
  1. Errai
  2. ERRAI-1081

@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS) breaks client demarshalling

    Details

    • Type: Enhancement
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      4.1.2-SNAPSHOT

      Description

      I am getting the following demarshalling exception while demarshalling a Long value when @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS) is a part of my circular reference support mixin. This basically just adds the `@class` full class name for deserialization, which probably isn't required for client demarshalling with Errai, however thought I'd log the issue incase anyone else has this issue and also thought it was very strange that it broke the demarshalling as it has.

      ErraiConsoleLogHandler.java:91 Error: RuntimeException: An error occurred while demarshalling the body of the response. 
          at nO_g$.HN_g$ [as createError_0_g$] (Throwable.java:120)
          at nO_g$.RN_g$ [as initializeBackingError_0_g$] (Throwable.java:112)
          at nO_g$.BN_g$ (Throwable.java:73)
          at nO_g$.fO_g$ (Exception.java:33)
          at new nO_g$ (RuntimeException.java:33)
          at D8j_g$.F8j_g$ [as onResponseReceived_0_g$] (AbstractJaxrsProxy.java:148)
          at u_d_g$.x_d_g$ [as fireOnResponseReceived_0_g$] (Request.java:250)
          at E0d_g$.F0d_g$ [as onReadyStateChange_0_g$] (RequestBuilder.java:412)
          at XMLHttpRequest.<anonymous> (XMLHttpRequest.java:329)
          at koc_g$ (Impl.java:309)
          at noc_g$ (Impl.java:361)
          at XMLHttpRequest.<anonymous> (Impl.java:78)
      $Hj_g$ @ ErraiConsoleLogHandler.java:91
      xIj_g$ @ ErraiConsoleLogHandler.java:91
      bIj_g$ @ ErraiConsoleLogHandler.java:103
      aIj_g$ @ ErraiConsoleLogHandler.java:96
      THj_g$ @ ErraiConsoleLogHandler.java:91
      cIj_g$ @ ErraiConsoleLogHandler.java:68
      QIi_g$ @ Logger.java:312
      PIi_g$ @ Logger.java:302
      kJi_g$ @ Logger.java:236
      Lpe_g$ @ LogConfiguration.java:169
      z$k_g$ @ ErraiUncaughtExceptionHandler.java:50
      K$k_g$ @ ErraiUncaughtExceptionHandler.java:50
      Fmi_g$ @ Optional.java:67
      B$k_g$ @ ErraiUncaughtExceptionHandler.java:50
      Doc_g$ @ Impl.java:256
      Coc_g$ @ Impl.java:238
      noc_g$ @ Impl.java:363
      (anonymous) @ Impl.java:78
      XMLHttpRequest.send (async)
      ODf_g$ @ XMLHttpRequest.java:305
      j0d_g$ @ RequestBuilder.java:418
      t0d_g$ @ RequestBuilder.java:261
      t8j_g$ @ AbstractJaxrsProxy.java:130
      s8j_g$ @ AbstractJaxrsProxy.java:116
      g9j_g$ @ JaxrsProxyLoaderImpl.java:43
      th_g$ @ HomePage.java:92
      Pf_g$ @ HomeController.java:49
      Vf_g$ @ HomeController.java:46
      rwj_g$ @ RpcProxyLoaderImpl.java:397
      epj_g$ @ DefaultRemoteCallBuilder.java:112
      Ksj_g$ @ ClientMessageBusImpl.java:697
      rsj_g$ @ ClientMessageBusImpl.java:859
      fBj_g$ @ BusToolsCli.java:54
      szj_g$ @ SSEHandler.java:147
      (anonymous) @ SSEHandler.java:174
      ErraiConsoleLogHandler.java:91 Error caused by: JavaScriptException: (TypeError) : Cannot read property 'isNumber_0_g$' of null
          at pjl_g$.ujl_g$ [as isNumber_1_g$] (GWTJSONValue.java:44)
          at Jml_g$.Kml_g$ [as doNotNullDemarshall_11_g$] (LongMarshaller.java:42)
          at Jml_g$.Lml_g$ [as doNotNullDemarshall_0_g$] (LongMarshaller.java:38)
          at Jml_g$.i7k_g$ [as demarshall_0_g$] (AbstractNullableMarshaller.java:35)
          at _9k_g$.aal_g$ [as demarshall_2_g$] (Marshaller_c_e_e_s_m_Pong_Impl.java:42)
          at _9k_g$.bal_g$ [as demarshall_0_g$] (Marshaller_c_e_e_s_m_Pong_Impl.java:18)
          at t6k_g$ (Marshalling.java:277)
          at p6k_g$ (Marshalling.java:249)
          at o6k_g$ (Marshalling.java:200)
          at F9j_g$.J9j_g$ [as fromJSON_2_g$] (MarshallingWrapper.java:73)
          at F9j_g$.K9j_g$ [as fromJSON_3_g$] (MarshallingWrapper.java:79)
          at w9j_g$ (MarshallingWrapper.java:128)
          at l9j_g$.m9j_g$ [as demarshallResponse_0_g$] (JaxrsProxyLoaderImpl.java:48)
          at D8j_g$.F8j_g$ [as onResponseReceived_0_g$] (AbstractJaxrsProxy.java:146)
          at u_d_g$.x_d_g$ [as fireOnResponseReceived_0_g$] (Request.java:250)
          at E0d_g$.F0d_g$ [as onReadyStateChange_0_g$] (RequestBuilder.java:412)
          at XMLHttpRequest.<anonymous> (XMLHttpRequest.java:329)
          at koc_g$ (Impl.java:309)
          at noc_g$ (Impl.java:361)
          at XMLHttpRequest.<anonymous> (Impl.java:78)
      

      I use Jackson to serialize on the server with erraiJaxRsJacksonMarshallingActive = true on the client

      This is the setup to reproduce this:

      public class Pong {
       
          private String id;
          private Long time;
       
          Pong child;
       
          public Pong() {
          }
       
          public Pong(String id, Long time) {
              this.id = id;
              this.time = time;
          }
       
          public String getId() {
              return id;
          }
       
          public void setId(String id) {
              this.id = id;
          }
       
          public Long getTime() {
              return time;
          }
       
          public void setTime(Long time) {
              this.time = time;
          }
       
          public Pong getChild() {
              return child;
          }
       
          public void setChild(Pong child) {
              this.child = child;
          }
      }
      

      Server:

      @Provider
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      public class JacksonMapperProvider implements ContextResolver<ObjectMapper> {
       
          private ObjectMapper objectMapper;
       
          public JacksonMapperProvider() {
              objectMapper = new JsonObjectMapper();
              objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
       
              // Do not serialize map key-value where value is null
              objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
       
              // Trying to ignore fields that have null values.
              objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
          }
       
          @Override
          public ObjectMapper getContext(Class type) {
              return objectMapper;
          }
      }
      

      public class JsonObjectMapper extends ObjectMapper {
       
          public JsonObjectMapper() {
              SerializationConfig serialConfig = getSerializationConfig()
                      .without(SerializationFeature.FAIL_ON_EMPTY_BEANS);
       
              DeserializationConfig deSerialConfig = getDeserializationConfig()
                      .without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
       
              setConfig(serialConfig);
              setConfig(deSerialConfig);
       
              setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
       
              // Support circular dependencies for all objects.
              addMixIn(Object.class, IdGeneratorMixin.class);
          }
      }
      

      @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS)
      @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
      public class IdGeneratorMixin {
      }
      

      Produces the follow JSON:

      {  
         "@class":"com.expansel.errai.springboot.model.Pong",
         "@id":1,
         "id":"ponged",
         "time":[  
            "java.lang.Long",
            1511123838328
         ],
         "child":1
      }
      

      Also see the image.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                mbarkley Max Barkley
                Reporter:
                ben.dol Ben Dol
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: