- Framework Spring MVC 4.x
- Hibernate 4.x
- Jackson 2.8
I have two columns one is publishDate
and createdDate
. Publish date user need to manually enter it. Created date in MySQL column has a default set as CURRENT_TIMESTAMP
, so when an entry is created DB will automatically timestamp the entry.
I have a book POJO publishDate
and createdDate
field... publishDate
can handle null data for some reason. But Timestamp field gets an exception. Why is this?
org.springframework.http.converter.HttpMessageNotWritableException: Could not
write content: (was java.lang.NullPointerException) (through reference chain:
java.util.HashMap["results"]->java.util.ArrayList[30]-
>com.app.books.Book["dateCreated"]); nested exception is
com.fasterxml.jackson.databind.JsonMappingException: (was
java.lang.NullPointerException) (through reference chain:
java.util.HashMap["results"]->java.util.ArrayList[30]-
>com.app.books.Book["dateCreated"])
I tried to suppress this by adding annotation, I tried several of them because I keep reading conflicting info on the comments section on which to use.
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) // but show JsonSerialize is deprecated
@JsonInclude(Include.NON_NULL)// Include can not be resolved as variable
@JsonInclude(JsonInclude.Include.NON_DEFAULT) // finally doesn't give me an error but I still get the same exception.
This is my book Class
@Entity
@Table(name="books")
@Component
public class Book implements Serializable{
/**
*
*/
private static final long serialVersionUID = -2042607611480064259L;
@Id
@GeneratedValue
private int id;
@NotBlank
private String name;
@NotBlank
@Size(min=2, max=16)
private String ispn;
@DecimalMin(value = "0.1")
private double price;
//@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
//@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
//@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
private Timestamp dateCreated;
private Date datePublished;
Very wried... Thanks for helping..