[英]How to save embedded object in POST call using Spring Data Rest
I am using Spring 1.3.3 and I am unable to use POST call for embedded object. 我正在使用Spring 1.3.3,并且无法对嵌入式对象使用POST调用。 Getting the following error while using POST call.. 使用POST呼叫时收到以下错误。
Request 请求
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"student": {
"address": {
.....
"zipcode": http://localhost:8082/zipcode/1,
}
},
"id": 1,
"zipcode": http://localhost:8082/zipcode/1,
"name": "John"
}' 'http://localhost:8082/student'
Response Error: 响应错误:
{
"cause": {
"cause": null,
"message": "Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]"
},
"message": "Could not read document: Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]"
}
Address.java Address.java
@Embeddable
public class Address {
private String street;
private String city;
private String state;
// getters and setters
Student.java Student.java
@Entity
@Table(name="Student")
@SecondaryTable(name="Student_ADDRESS",
pkJoinColumns=@PrimaryKeyJoinColumn(name="Student_ID"))
public class Student {
@Id private int id;
private String name;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="street", column=@Column(table="Student_ADDRESS")),
@AttributeOverride(name="city", column=@Column(name="CITY", table="Student_ADDRESS")),
@AttributeOverride(name="state", column=@Column(name="STATE", table="Student_ADDRESS")),
})
private Address address;
private Zipcode zipcode;
//getters and setters
Zipcode.java Zipcode.java
@Entity
public class Zipcode {
@Id
public int id;
public String code;
}
How to save embedded object? 如何保存嵌入式对象? Kindly provide your inputs. 请提供您的输入。
It tells you that you should put "" around the urls. 它告诉您应该在网址周围加上“”。
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"student": {
"address": {
.....
"zipcode": "http://localhost:8082/zipcode/1",
}
},
"id": 1,
"zipcode": "http://localhost:8082/zipcode/1",
"name": "John"
}' 'http://localhost:8082/student'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.