0

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

  1. How do i specify which parser spring uses for the mapping?
  2. How do i override the settings to that parser using either annotation xml?
  3. 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);
    }
}
JamesENL
  • 6,400
  • 6
  • 39
  • 64
kevinn2065
  • 325
  • 1
  • 3
  • 12
  • Please refer to the post below: http://stackoverflow.com/questions/25646564/unable-to-convert-string-to-date-by-requestbody-in-spring – shankarsh15 May 16 '16 at 03:51
  • One of the issues is that my mapper is defaulting to gson so jacksons settings wont help unless i can figure out how to switch it to use jackson – kevinn2065 May 16 '16 at 04:10

0 Answers0