简体   繁体   中英

@RequestBody doesn't work as expected

I am sending a JSON obj to the server which will populate my domain obj Report.

public class CustomReport {String name;
String name;
String email;
Date invocieDate;
Date shipDate;
//...getters and setters
}

everything are populated but invoiceDate.

public void create(@RequestBody CustomReport report, HttpServletRequest request) {      
      System.out.println(report.getShipDate()); 
      System.out.println(report.getInvocieDate()); // gives me null
      System.out.println(report.getName());
}

I checked the request payload from the browser, i think the request is ok

{"name":"trace","email":"trace@gmail.com","invoiceDate":"2015-01-01T06:00:00.000Z","shipDate":"2015-01-02T06:00:00.000Z"}

my js code is as following:

    $scope.submit = function() {
    console.log($scope.report.invoiceDate); //got value here
    $http.post('/api/request/submit', $scope.report).success(function(data){
        alert("success");
    }).error(function(data,status,headers,config){});

is there anything wrong with my code? anything I could do to debug?

please help, any help will be appreciated.

Look more carefully

in the JSON:

"invoiceDate":"2015-01-01T06:00:00.000Z" 

in the class

Date invocieDate;

In both a name should be the same)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM