你好(对不起我的英文)
我正在使用angularjs前端网站,使用SPRING MVC生成json的web服务.spring mvc使用JsonIdentityInfo选项进行seralization,因此每个对象只在json中写入一次,并且每次使用一个引用,例如她有2个"计算机"使用相同的对象"component",所以spring将id设置为第一个组件("@componentID":2)和第二个组件juste id(2):
[
{
"@computerID": 1,
"component": {
"@componentID": 2,
"processor": 2,
"ram": "8g",
"harddrive": "wd"
}
},
{
"@computerID": 3,
"component": 2
}
]
Run Code Online (Sandbox Code Playgroud)
我想要的是 :
[
{
"@computerID": 1,
"owner" : "Mister B",
"component": {
"@componentID": 2,
"processor": 2,
"ram": "8g",
"harddrive": "wd"
}
},
{
"@computerID": 3,
"owner" : "Mister A",
"component": {
"@componentID": 2,
"processor": 2,
"ram": "8g",
"harddrive": "wd"
}
}
]
Run Code Online (Sandbox Code Playgroud)
我做了很多搜索代码谁做了这个,但我没有发现任何想法.
我无法编辑Web服务以删除此行为.我可以使用javascript或jquery(或其他librairie)编辑客户端的json,以用真实引用的对象替换引用吗?(数据实际上更复杂,更深,我在对象中有3级子对象).
非常感谢.
我在这个Web服务项目中使用Spring(xml + annotations),Hibernate(注释).数据库关系图,模型,预期和实际输出如下,
Customer.java
@Entity
@Table(name="customer")
public class Customer implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="customer_id", unique=true, nullable =false)
long customerId;
@Column(name="name")
String name;
@Column(name="secondary_name")
String secondaryName;
@Column(name="date")
Date date;
@Column(name="address")
String address;
@Column(name="post")
String post;
@Column(name="pin")
String pin;
@Column(name="phone")
String phone;
@OneToMany(fetch=FetchType.LAZY, mappedBy="customer", cascade=CascadeType.ALL)
@JsonManagedReference
Set<Loan> loans = new HashSet<Loan>();
//constructors, getters and setters
}
Run Code Online (Sandbox Code Playgroud)
Loan.java
public class Loan implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY) …Run Code Online (Sandbox Code Playgroud) angularjs ×1
hibernate ×1
jackson ×1
javascript ×1
json ×1
one-to-many ×1
spring ×1
spring-mvc ×1