How to set datetime formatting in joda, jackson, hibernate.
import org.joda.time.DateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
//other imports...
@Entity
public class Example {
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@JsonFormat(pattern = "dd/MM/yyyy'T'HH:mm")
private DateTime eventDateTime;
//getters setters
}
//registration joda jackson module:
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JodaModule());
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false);
DateFormat df = new SimpleDateFormat("dd/MM/yyyy'T'HH:mm");
objectMapper.setDateFormat(df);
//If I send JSON like:
{"eventDateTime": "19/05/2014T14:8"}
//my spring controller:
@RequestMapping(method = RequestMethod.POST)
public void saveExample(@RequestBody Example example ) { ..
My Spring controller always fails in de-serialization eventDateTime so I'm getting response error 400 "The request sent by the client was syntactically incorrect".
If I change datetime formatting to:
{"eventDateTime": "2014-05-19T14:8"}
and it works.