JacksonMapper to zero-deserialize

I am going to deserialize a Json null value for Java Object empty string

I can create my own deserializer, but when the Json value is null, it does not fall into the deserializer.

How to deserialize it?

Thanks in advance!

public class CustomStringDeserializer extends JsonDeserializer<String> { @Override public String deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) throws IOException, JsonProcessingException { String str = jsonparser.getText(); try { return (str == null) ? "" : str; } catch (Exception e) { throw new RuntimeException(e); } } 

}

  public CustomObjectMapper() { SimpleModule _module = new SimpleModule("Module", new Version(1, 9, 10, "FINAL")); _module.addDeserializer(String.class, new CustomStringDeserializer()); } 


Thanks @nutlike
I'm doing it

  @Override public String getNullValue() { return ""; } 
+4
source share
1 answer

Maybe just rewriting the getNullValue () method is enough ?

 public class CustomStringDeserializer extends JsonDeserializer<String> { @Override public String deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) throws IOException, JsonProcessingException { return jsonparser.getText(); } @Override public String getNullValue() { return ""; } } 
+2
source

Source: https://habr.com/ru/post/1480860/


All Articles