@Override
  public byte[] toBytes(T obj) {
    if (obj != null) {
      try {
        String str = mapper.writeValueAsString(obj);
        return str.getBytes("UTF-8");
      } catch (Exception e) {
        throw new SamzaException("Error serializing data.", e);
      }
    } else {
      return null;
    }
  }
Constructs a JsonSerdeV2 that (de)serializes POJOs of class {@code clazz}.

@param clazz the class of the POJO being (de)serialized.
samza-api/src/main/java/org/apache/samza/serializers/JsonSerdeV2.java