鉴于JPA-RS示例here,我将地址的新属性添加到Student
类:
@Embedded
@XmlPath(".")
private Address address;
Address
类:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Embeddable
public class Address implements Serializable {
private static final long serialVersionUID = 1L;
private String streetName;
private int streetNumber;
private int zipCode;
private String city;
// constructor, getters, etc.
}
访问元数据网址http://host:port/context-root/persistence/persistence-unit/metadata/entity/Student
时,它会描述模型而不嵌入新添加的属性的属性:
{
"name": "Student",
"attributes": [
{
"name": "id",
"type": "Long"
},
{
"name": "name",
"type": "String"
},
{
"name": "address",
"type": "Address"
},
{
"name": "courses",
"type": "List<Course>"
}
],
但它在发送这样的对象时确实有效,并且它使用GET返回此表单中的对象:
{
"name": "John",
"streetName": "Rue Doe",
"streetNumber": 123,
"zipCode": 45678,
"city": "Samplesten"
}
我的问题:这是预期的行为吗?假设我想使用元数据api为用户提供有关他们必须使用的一般模型的知识。目前的设计极具误导性。同样适用于重命名属性。