org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.NullPointerException) (through reference chain: in.xyz.sync.dto.ClassRoom["id"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: in.xyz.sync.dto.ClassRoom["id"])
import java.util.List;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ClassRoom extends CommonResponse {
private long classId;
private String clientClassRoomId;
private long instituteId;
private long teacherId;
private String className;
private long handleId;
private int archived;
private int deleted;
private String creationTime;
private String modifiedTime;
private int type;
private String classCode;
private List<Student> student;
private String handle;
private String firstName;
}
You may have better results switching from primitives (int & long) to Java classes (Int & Long) in your ClassRoom class. See JsonMappingException (was java.lang.NullPointerException)
You might also have luck pinning down which field is null by assigning @NotNull (javax.validation.constraints.NotNull) to all of your fields. If you are encountering a null value, the @NotNull annotation will cause a runtime exception. Then, comment out the @NotNull annotations one by one until the exception goes away and you will find the culprit (or at least the first one of them if there are more than one).
In my case, i just had to replace the int by Integer:
e.g.:
private int idtask; => private Integer idtask;
Did the same for getter and setter.
public Integer getIdlayer() {
return idlayer;
}
public void setIdlayer(Integer idlayer) {
this.idlayer = idlayer;
}
This solved my issue. Basically i was having this issue because there was a null value in this column. Using: Spring Boot + PostgreSQL
Note: Dave McLure' answer is the solution too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With