@Converter(autoApply = true)
public class Test implements AttributeConverter<TestObj, String> {
@Autowired
private ObjectMapper mapper;
@Override
public String convertToDatabaseColumn(TestObj object) {
try {
return mapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
return null;
}
}
@Override
public TestObj convertToEntityAttribute(String s) {
try {
return mapper.readValue(s, TestObj.class);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
The above code causes NullPointerException
as the mapper
object is not initialized. It worked when I didn't add,
@Converter(autoApply = true)
Any idea how do I get this working? I am using this in a spring boot application.