I'm trying to get the requestBody to automatically map to an class, but i'm having issues with the object being rejected because of the date
Spring Version 4.1 - It appears that spring is using gson instead of jackson
Could you please help with the following
- How do i specify which parser spring uses for the mapping?
- How do i override the settings to that parser using either annotation xml?
- is there any other information that would be helpful?
I've tried some thing like this but they dont seem to work
@Type(type="timestamp")
//@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm a z")
//@JsonDeserialize(using = DateDeserializer.class)
//@JsonSerialize(using = CustomDateSerializer.class)
@Column(name = "date")
private Date date;
I've also tried manually setting a gson parser to user a specific date format which worked but i cant seem to figure out how to ovveride the one that spring is using
gsonBuilder.setDateFormat("MM-dd-yyyy");
"org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: 05/17/2016; nested exception is com.google.gson.JsonSyntaxException: 05/17/2016"
@RequestMapping(value = "/saveIdea", method = RequestMethod.POST)
public @ResponseBody ResponseEntity saveIdea(@RequestBody Idea idea) throws IOException {}
Heres one way i tried to override it, it doesnt seem to be using this
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//converters.add(new ExtendedGsonHttpMessageConverter());
GsonHttpMessageConverter msgConverter = new GsonHttpMessageConverter();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
msgConverter.setGson(gson);
converters.add(msgConverter);
}
}