Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

In Java Spring MVC project, I post an object to a @RestController and the object I post has an date property. If I remove this property, the post works successfully. But with the date property, it returns a 400 bad request. In the dto the Date is java.util.Date

Method in controller:

@RequestMapping(value = "/users/createPetition", method = RequestMethod.POST)
public @ResponseBody PetitionDTO addPetition(@RequestBody PetitionRequestDTO petitionDto, Model model) {   ...

PetitionRequestDTO

public class PetitionRequestDTO {

private Long userId;

private Long categoryId;

private String title;

private String description;

private Date initialDate;

private String address; //getters setters

The angular js call

if ($scope.petitionForm.$valid) {
        $http.post(getCompletePath("users/createPetition"), JSON.stringify($scope.newPetition))
        .success(function (petition) {

        }).error(function (data, status, headers, config) {

        });

In the js the date has the next value: Thu Mar 19 2015 00:00:00 GMT-0300 (Argentina Standard Time)

The complete json is:

"{"selectedCategory":{"id":3,"name":"Plomero","description":"Plomeria"},"name":"aaa","title":"bbb","description":"ccc","initialDate":"2015-03-19T03:00:00.000Z","address":"asd","categoryId":3}"
share|improve this question

1 Answer 1

You need to ensure a better format in your JS code for the JSON Date. There is a discussion here that you should consider - The "right" JSON date format.

Once you have this in order you need a corresponding Date Time Formatter in Spring MVC to be able to convert the JSON Date String into Date Object - spring mvc date format with form:input; and here's another example.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.