title: Hazelcast: Global Jackson-Smile Byte-Array Serializer and Generics
body: <p>I'm trying to register a global serializer using jackson-smile for hazelcast.</p>
  
  <pre><code>public class GlobalJacksonSmileSerializer implements ByteArraySerializer&lt;Object&gt; {
      private final ObjectMapper mapper = new ObjectMapper(new SmileFactory());
      public int getTypeId() { return 1; }
  
      public void destroy() { }
  
      @Override
      public byte[] write(final Object object) throws IOException {
          return mapper.writeValueAsBytes(object);
      }
  
      @Override
      public Object read(final byte[] bytes) throws IOException {
          return mapper.readValue(bytes, Object.class);
      }
  }
  </code></pre>
  
  <p>When deserializing an object containing a generic collection, e.g.</p>
  
  <pre><code>public class Foo {
      private List&lt;Bar&gt; bars;
  }
  </code></pre>
  
  <p>it fails:</p>
  
  <pre><code>Caused by: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to Bar
  </code></pre>
  
  <p>According to other answers here on stackoverflow (e.g. <a href="https://stackoverflow.com/questions/28821715/java-lang-classcastexception-java-util-linkedhashmap-cannot-be-cast-to-com-test">java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.testing.models.Account</a>) this is a jackson limitation.</p>
  
  <p>Since this is a global byte-array serializer, I can not be more specific about collection-types. Is there a way to handle this other than implement a serializer for each class?</p>