Trying to deserialize LocalDateTime throws strange errors

Question

I am passing from frontend - Angular 4 the array of objects in which some of them are date objects which in backend there are mapped as LocalDateTime. Unfortunately when I try to deserialize by my own deserializator I got an error which is quite obvious for me but I can't solve it. So my java classes looks like:

Deserializator:

public class DateDeserialization extends JsonDeserializer<LocalDateTime> {
    @Override
    public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
      return LocalDateTime.parse(jsonParser.getText());
    }
}

My model class in which I add above deserializator to the field:

   @JsonFormat(pattern = "MM-dd-yyyy")
    @JsonDeserialize(using = DateDeserialization.class)
    private LocalDateTime insertDate;

And my java controller:

@RequestMapping(value = "", method = RequestMethod.POST)
public List<Guide> save(@RequestBody List<Guide> guides) {
    guides.stream().forEach(x -> {
        guideService.save(x);
    });
    return null;
}

The error which I get is a 404 bad request and error message is:

JSON parse error: Text '{' could not be parsed at index 0; nested exception is com.fasterxml.jackson.databind.JsonMappingException

Of course I know what does it mean but how to solve it? I also tried browser debugger what is passing to the backend when the request is send and:

0:{id: 1, description: "test1", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
1:{id: 2, description: "test12", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
2:{id: 3, description: "test13", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
3:{id: 4, description: "test14", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
4:{id: 5, description: "test15", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}

UPDATE:

  ngOnInit() {
    this.guideService.getAll()
      .subscribe(res => {
        this.guides = res.json();
      });
  }

  save(){
    this.guideService.insertOrUpdate(this.guides).subscribe(res => {
      console.log("test went")
    });
  }

Show source
| java   | date   | deserialization   | angular   | json-deserialization   2017-10-04 22:10 0 Answers

Answers to Trying to deserialize LocalDateTime throws strange errors ( 0 )

Leave a reply to - Trying to deserialize LocalDateTime throws strange errors

◀ Go back