Created
July 28, 2014 13:24
-
-
Save qerub/96104c9844aa399b679e to your computer and use it in GitHub Desktop.
Integrating Thrift's JSON serializer with Jackson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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