REST Post中的一个属性导致null

时间:2016-05-30 22:45:25

标签: spring rest post curl spring-data

我正在开发一个宁静的Spring应用程序。 我有一个休息资源,如下所示:

{
  "_embedded" : {
    "timestamps" : [ {
      "timestamp" : "2016-04-28T08:48:13.000Z",
      "peopleIn" : 3,
      "peopleOut" : 0,
      "currentAttendance" : 11,
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/timestamps/11"
        },
        "timestamp" : {
          "href" : "http://localhost:8080/timestamps/11"
        },
        "venue" : {
          "href" : "http://localhost:8080/timestamps/11/venue"
        }
      }
    }, {
      "timestamp" : "2016-04-28T11:48:13.000Z",
.....etc

现在,当我想在时间戳中添加另一行时,我使用基本身份验证在curl中使用以下POST:

curl -i -X POST -v -u exampleUser:pass -H "Content-Type:application/json" -d '{ "timestamp" : "2016-04-16T08:17:20.000Z", "peopleIn" : "1", "peopleOut":"0", "currentAttendance" : "10", "venue": "localhost://8080/venues/6" }' http://localhost:8080/timestamps

我的问题是它导致以下结果:

{
  "timestamp" : "2016-04-16T08:17:20.000Z",
  "peopleIn" : 1,
  "peopleOut" : 0,
  "currentAttendance" : null,
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/timestamps/1498"
    },
    "timestamp" : {
      "href" : "http://localhost:8080/timestamps/1498"
    },
    "venue" : {
      "href" : "http://localhost:8080/1498/venue"
    }
  }

为什么timestamp,peopleIn,peopleOut和venue的值是如何发布但currentAttendance的值为null ???

编辑: 我的Timestamp类(使用JPA)如下:

@Configuration
public class Timestamp {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    private DateTime timestamp;

    @ManyToOne
    @JoinColumn(name = "venue_id")
    private Venue venue;

    private Integer peopleIn;

    private Integer peopleOut;

    private Integer currentAttendance;

    public Timestamp() {}

    public Timestamp(DateTime timestamp, Integer peopleIn, Integer peopleOut, Venue venue, Integer currentAttendance) {
        this.timestamp = timestamp;
        this.peopleIn = peopleIn;
        this.peopleOut = peopleOut;
        this.venue = venue;
        this.currentAttendance = currentAttendance;
    }

    public DateTime getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(DateTime timestamp) {
        this.timestamp = timestamp;
    }

    public Venue getVenue() {return venue;}

    public void setVenue(Venue venue) {this.venue = venue;}

    public Integer getPeopleIn() {return peopleIn;}

    public void setPeopleIn(Integer peopleIn) {this.peopleIn = peopleIn;}

    public Integer getPeopleOut() {return peopleOut;}

    public void setPeopleOut(Integer peopleOut) {this.peopleOut = peopleOut;}

    public Integer getCurrentAttendance() {return currentAttendance;}

    public void setCurrentAttendance(Integer peopleIn) {this.peopleIn =     currentAttendance;}

}

0 个答案:

没有答案