Skip to content

Instantly share code, notes, and snippets.

@qerub
Created July 28, 2014 13:24
Show Gist options
  • Save qerub/96104c9844aa399b679e to your computer and use it in GitHub Desktop.
Save qerub/96104c9844aa399b679e to your computer and use it in GitHub Desktop.
Integrating Thrift's JSON serializer with Jackson
class ThriftSerializer extends JsonSerializer<TBase> {
@Override
public void serialize(TBase value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
try {
TProtocolFactory f = new TSimpleJSONProtocol.Factory();
String s = new TSerializer(f).toString(value);
jgen.writeRawValue(s);
}
catch (TException e) {
throw new IOException(e);
}
}
}
ObjectMapper objectMapper = new ObjectMapper();
CustomSerializerFactory serializerFactory = new CustomSerializerFactory();
serializerFactory.addGenericMapping(TBase.class, new ThriftSerializer());
objectMapper.setSerializerFactory(serializerFactory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment