title: Jackson Custom Deserializer Not Working In Spring Boot
body: <p>I created a custom deserializer for my entities but it keeps on throwing exception:</p>
  <p>I have two classes: AppUser and AppUserAvatar</p>
  <p><strong>AppUser.java</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;user&quot;)
  public class AppUser implements Serializable {
  
      @Transient
      private static final long serialVersionUID = -3536455219051825651L;
  
      @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
      @Column(name = &quot;password&quot;, nullable = false, length = 256)
      private String password;
  
      @JsonIgnore
      @Column(name = &quot;is_active&quot;, nullable = false)
      private boolean active;
  
      @JsonIgnore
      @OneToMany(mappedBy = &quot;appUser&quot;, targetEntity = AppUserAvatar.class, fetch = FetchType.LAZY)
      private List&lt;AppUserAvatar&gt; appUserAvatars;
  
      //// Getters and Setters and toString() ////
  }
  </code></pre>
  <p><strong>AppUserAvatar.java</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;user_avatar&quot;)
  public class AppUserAvatar extends BaseEntityD implements Serializable {
  
      @Transient
      private static final long serialVersionUID = 8992425872747011681L;
  
      @Column(name = &quot;avatar&quot;, nullable = false)
      @Digits(integer = 20, fraction = 0)
      @NotEmpty
      private Long avatar;
  
      @JsonDeserialize(using = AppUserDeserializer.class)
      @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;user_id&quot;, nullable = false)
      private AppUser appUser;
  
      //// Getters and Setters and toString() ////
  }
  </code></pre>
  <p><strong>AppUserDeserializer.java</strong>
  package com.nk.accountservice.deserializer;</p>
  <pre><code>import com.edoctar.accountservice.config.exception.InputNotFoundException;
  import com.edoctar.accountservice.domain.candidate.AppUser;
  import com.edoctar.accountservice.service.candidate.AppUserService;
  import com.fasterxml.jackson.core.JsonParser;
  import com.fasterxml.jackson.databind.DeserializationContext;
  import com.fasterxml.jackson.databind.JsonDeserializer;
  import com.fasterxml.jackson.databind.JsonNode;
  import org.springframework.beans.factory.annotation.Autowired;
  
  import java.io.IOException;
  import java.io.Serializable;
  
  public class AppUserDeserializer extends JsonDeserializer implements Serializable {
  
      private static final long serialVersionUID = -9012464195937554378L;
  
      private AppUserService appUserService;
  
      @Autowired
      public void setAppUserService(AppUserService appUserService) {
          this.appUserService = appUserService;
      }
  
      @Override
      public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
          JsonNode node = jsonParser.getCodec().readTree(jsonParser);
          Long userId = node.asLong();
          System.out.println(node);
          System.out.println(node.asLong());
          AppUser appUser = appUserService.findById(userId);
          System.out.println(&quot;appuser: &quot; + appUser);
          if (appUser == null) try {
              throw new InputNotFoundException(&quot;User not found!&quot;);
          } catch (InputNotFoundException e) {
              e.printStackTrace();
              return null;
          }
  
          return appUser;
      }
  }
  </code></pre>
  <p>Sample xhr boy is:</p>
  <pre><code>{
    &quot;appUser&quot;: 1,
    &quot;avatar&quot;: 1
  }
  </code></pre>
  <p>An exception is thrown each time I submit the request.</p>
  <pre><code>Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.edoctar.accountservice.domain.candidate.AppUserAvatar[&quot;appUser&quot;])]
  </code></pre>
  <p><a href="https://i.stack.imgur.com/bF0k3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bF0k3.png" alt="Here's the screenshoot of my console." /></a></p>
  <p>I discovered that the <code>appUserService.findById()</code> method is not being called. I am really confused. I don't know where I went wrong. Will be greatful for any solution. Thanks.</p>