Doc说,@Field
注释可用于重命名实体中的字段。嵌套POJO中的字段在技术上不是实体本身怎么办?考虑以下假设示例。
@Document
public class Person {
@Id
private String ssn;
@Field
private String name;
@Field
private Address address;
static class Address {
// how to rename this field to line1?
private String street;
}
}
具体回答你的问题,你可以使用@Field("line1")
的street
在Address
。
我的项目中有类似的内容,并且效果很好(请参阅descriptions
)
1类
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HotelInfo {
@Field("hotel_type") @JsonProperty("hotel_type")
public String hotelType;
@Field @JsonProperty("images")
public List<Image> images = new ArrayList<Image>();
@Field @JsonProperty("regions")
public List<String> regions = new ArrayList<String>();
@Field @JsonProperty("themes")
public List<String> themes = new ArrayList<String>();
@Field @JsonProperty("facilities")
public List<String> facilities;
@Field @JsonProperty("descriptions")
public Descriptions descriptions;
}
2级
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Descriptions {
@Field("hotel_information") @JsonProperty("hotel_information")
public String hotelInformation;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句