I want to enable a custom jackson deserializer of some fields of type String. The deserializer also needs to be injected with a guice based dependency bean. SampleCode below:
public class CustomDeserializer extends StdDeserializer<String> {
private SomeDependecy dependency;
public StringDeserializer() {
this(null);
}
public StringDeserializer(Class<?> vc) {
super(vc);
}
@Override
public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
return dependency.perform(p.getValueAsString());
}
}
I cannot register a module based on Class type as it is generic (String.class, Complex Datatype( but not every one require a custome deserializer)). Is there a way to achieve the above without using static methods?
PS: I did search net but could not find a cleaner solution without using statics . All the suggestions where around using Some static method to get context and bean.