Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.