Flint Flint - 1 month ago 8
Java Question

Json parsing error for date with Jackson

I am trying to parse json data with date field (Jul 6 1989 12:00AM).

@Column(name = "datescan", columnDefinition = "DateTime")
@JsonProperty("DateScan")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MMM d yyyy hh:mm a", locale = "us")
Date dateScan;


Error

com.fasterxml.jackson.databind.JsonMappingException: Failed to parse Date value 'Jul 6 1989 12:00AM' (format: "MMM d yyyy hh:mm a"): Unparseable date: "Jul 6 1989 12:00AM" (through reference chain: org.temp.model.DataBMD["data"]->java.util.ArrayList[0]->org.temp.model.BoneMineralDensity["DateScan"])

Caused by: java.lang.IllegalArgumentException: Failed to parse Date value 'Jul 6 1989 12:00AM' (format: "MMM d yyyy hh:mm a"): Unparseable date: "Jul 6 1989 12:00AM"

Answer

A little space in your format is causing all trouble.

Try this pattern: pattern = "MMM d yyyy hh:mma" as date you have provided doesn't contain any space between minutes and AM.