Example #1
0
  @Override
  public void serialize(OutputStream out, Record record) throws RecordSerializationException {

    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    module.addSerializer(StandardRecord.class, new EventSerializer());
    mapper.registerModule(module);

    // map json to student

    try {
      mapper.enable(SerializationFeature.INDENT_OUTPUT);
      mapper.setPropertyNamingStrategy(
          PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
      String jsonString = mapper.writeValueAsString(record);

      out.write(jsonString.getBytes());
      out.flush();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }