// [Issue#227]
 public void testGenericEnumSerializer() throws Exception {
   // By default, serialize using name
   ObjectMapper m = new ObjectMapper();
   SimpleModule module = new SimpleModule("foobar");
   module.addSerializer(Enum.class, new LowerCasingEnumSerializer());
   m.registerModule(module);
   assertEquals(quote("b"), m.writeValueAsString(TestEnum.B));
 }
Пример #2
0
  @Override
  public Record deserialize(InputStream in) throws RecordSerializationException {

    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    module.addDeserializer(Record.class, new EventDeserializer());
    mapper.registerModule(module);

    Record record = null;
    try {
      record = mapper.readValue(in, Record.class);
    } catch (IOException e) {
      e.printStackTrace();
    }

    return record;
  }
Пример #3
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();
    }
  }