title: Jackson Deserialization - JsonMappingException on a null object reference
body: <p>I have my object newNote of type Note. I'm composing the object (using Jackson library) by adding values to newNote and that's ok but when I try to do:</p>
  
  <pre><code>String bodyRequest = mapper.writeValueAsString(newNote);
  </code></pre>
  
  <p>I have JsonMappingException on a null object reference.</p>
  
  <p>I'm trying to compose the body of a POST Request to insert here:</p>
  
  <pre><code>URL url = new URL("http://myUrl");
  
              HttpURLConnection connection = (HttpURLConnection)url.openConnection();
              connection.setRequestMethod("POST");
              connection.setRequestProperty("Content-Type", "application/json");
              connection.setRequestProperty("Authorization", mAuth);
              connection.setDoOutput(true);
  
              //here I try to set up the body
              String bodyRequest = mapper.writeValueAsString(newNote);
  
  
  
              DataOutputStream dStream = new DataOutputStream(connection.getOutputStream());
  
              //here I have the other problem
              dStream.writeBytes(bodyRequest);
              dStream.flush();
              dStream.close();
  </code></pre>
  
  <p>but I have error also when I try to:</p>
  
  <pre><code>dStream.writeBytes(bodyRequest);
  </code></pre>
  
  <p>I configure my ObjectMapper like this:</p>
  
  <pre><code>mapper = new ObjectMapper();
                  mapper.registerModule(new ThreeTenModule());
                  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
                  mapper.enable(SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID);
                  mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
                  mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
                  mapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, false);
                  mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
                  mapper.configure(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, false);
                  mapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, false);
                  mapper.configure(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, false);
  </code></pre>
  
  <p>and my Note class is:</p>
  
  <pre><code>@Entity
  @JsonIdentityInfo(generator = IdentityGenerator.class)
  @JsonIgnoreProperties(ignoreUnknown = true)
  
  public class Note {
  
  @Id
  private Long id;
  private User author;
  private ZonedDateTime created;
  private String content;
  private Status status;
  private User assignee;
  private Activity activity;
  private List&lt;File&gt; attachments = new ArrayList&lt;&gt;();
  private Boolean restricted;  
  private Status NextStatus;
  private User NextAssignee;
  
  ...
  //setters and getters
  //hashcode and equals methods
  ...
  }
  </code></pre>
  
  <p>How can I do?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is my stacktrace:</p>
  
  <pre><code>05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:       com.fasterxml.jackson.databind.JsonMappingException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:141)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3613)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2980)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at it.prova.www.b.TicketsNewNotes$PostAsyncCaller.doInBackground(TicketsNewNotes.java:399)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at it.prova.www.b.TicketsNewNotes$PostAsyncCaller.doInBackground(TicketsNewNotes.java:342)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at java.lang.Thread.run(Thread.java:818)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at it.prova.www.b.best.base.dto.identity.IdentityGenerator.generateId(IdentityGenerator.java:73)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at it.prova.www.b.best.base.dto.identity.IdentityGenerator.generateId(IdentityGenerator.java:12)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at com.fasterxml.jackson.databind.ser.impl.WritableObjectId.generateId(WritableObjectId.java:43)
  05-04 11:32:48.259 4754-5030/it.prova.www.b W/System.err:     at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase._serializeWithObjectId(BeanSerializerBase.java:588)
  05-04 11:32:48.260 4754-5030/it.prova.www.b W/System.err:     at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:148)
  05-04 11:32:48.260 4754-5030/it.prova.www.b W/System.err:     at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:130)
  05-04 11:32:48.260 4754-5030/it.prova.www.b W/System.err:   ... 10 more
  </code></pre>