Uploaded image for project: 'Samza'
  1. Samza
  2. SAMZA-933

SamzaObjectMapper used in JsonSerde has disabled the auto_detect_getters

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: 0.10.1
    • Component/s: container
    • Labels:
      None

      Description

      Find there is a bug in the new version JsonSerde file in Samza 0.10.0, it replaced the codehaus ObjectMapper with SamzaObjectMapper and in the SamzaObjectMapper there is one line:

      mapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, false);

      In the code comment we can see:

      /**

      • Feature that determines whether regualr "getter" methods are
      • automatically detected based on standard Bean naming convention
      • or not. If yes, then all public zero-argument methods that
      • start with prefix "get"
      • are considered as getters.
      • If disabled, only methods explicitly annotated are considered getters.
        *<p>
      • Note that since version 1.3, this does <b>NOT</b> include
      • "is getters" (see
        Unknown macro: {@link #AUTO_DETECT_IS_GETTERS}

        for details)
        *<p>

      • Note that this feature has lower precedence than per-class
      • annotations, and is only used if there isn't more granular
      • configuration available.
        *<P>
      • Feature is enabled by default.
        */
        AUTO_DETECT_GETTERS(true),

      Which causes the Serde fail to serialize the HashMap entry object in hello-athena example.
      To verify that, I wrote a simple code to test it out:

      package com.uber.athena;

      import java.util.HashMap;
      import java.util.Map;

      import org.apache.samza.serializers.JsonSerde;

      public class SerializationHMEntry {
      public static void main(String[] args) {
      JsonSerde jsonSerde = new JsonSerde();
      Map<String, Long> dummyHashMap = new HashMap<>();
      dummyHashMap.put("key1", 1L);
      for (Map.Entry<String, Long> entry : dummyHashMap.entrySet())

      Unknown macro: { byte[] bytes = jsonSerde.toBytes(entry); System.out.println(bytes.toString()); }

      }
      }

      The output exception is as below:

      Exception in thread "main" org.apache.samza.SamzaException: org.codehaus.jackson.map.JsonMappingException: No serializer found for class java.util.HashMap$Node and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) )
      at org.apache.samza.serializers.JsonSerde.toBytes(JsonSerde.scala:36)
      at com.uber.athena.SerializationHMEntry.main(SerializationHMEntry.java:16)
      Caused by: org.codehaus.jackson.map.JsonMappingException: No serializer found for class java.util.HashMap$Node and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) )
      at org.codehaus.jackson.map.ser.StdSerializerProvider$1.failForEmpty(StdSerializerProvider.java:89)
      at org.codehaus.jackson.map.ser.StdSerializerProvider$1.serialize(StdSerializerProvider.java:62)
      at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:600)
      at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:280)
      at org.codehaus.jackson.map.ObjectMapper._configAndWriteValue(ObjectMapper.java:2260)
      at org.codehaus.jackson.map.ObjectMapper.writeValueAsString(ObjectMapper.java:1829)
      at org.apache.samza.serializers.JsonSerde.toBytes(JsonSerde.scala:33)
      ... 1 more

      And if commented out that line in the Samza 0.10.0 SamzaObjectMapper file and rebuild Samza as the dependency, the sample code works fine.

        Attachments

          Activity

            People

            • Assignee:
              Yuanchi Yuanchi Ning
              Reporter:
              Yuanchi Yuanchi Ning
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: