title: How to configure JSON deserialization in Spring to set null values if JSON property is empty string?
body: <p>I created custom JsonDeserializer for that can be applied to any field with type String.</p>
  
  <pre><code>public class EmptyToNullStringDeserializer extends JsonDeserializer&lt;String&gt; {
      @Override
      public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
          String text = jp.getText();
          return "" == text ? null : text;
      }
  }
  </code></pre>
  
  <p>It can be used in models.</p>
  
  <pre><code>class SomeClass {
      @JsonDeserialize(using = EmptyToNullStringDeserializer.class)
      private String someField;
  }
  </code></pre>
  
  <p>It converts JSON</p>
  
  <pre><code>{"someField": ""}
  </code></pre>
  
  <p>into Java object where <code>someField</code> equals to <code>null</code> (not <code>""</code>)</p>
  
  <p><strong>Question:</strong> How to create generic <code>JsonDeserializer</code> that sets <code>null</code> to all Java object fields that equals to <code>""</code> in JSON?
  It should be used as:</p>
  
  <pre><code>@JsonDeserialize(using = EmptyToNullStringDeserializer.class)
  class SomeClass {
          private String someField;
  }
  </code></pre>