I would like to create some serializers which are aware of some of my spring beans. The best way seems so far to me is extending DefaultSerializerProvider but I could not be sure.
@Component
public class PhotoSerializer extends JsonSerializer<String> {
@Autowired
Service service;
@Override
public void serialize(String value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeString(service.doIt(value));
}
}
What is the correct way of creating some serializers by Spring?
You can use Jackson HandlerInstantiator to build a bridge between spring and jackson serializer.
It is well described here :
http://www.runningasroot.com/blog/2012/05/02/autowiring-jackson-deserializers-in-spring/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With