0

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;
    }
}
4

1 回答 1

1

要具体回答您的问题,您可以使用@Field("line1")for streetin 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;
}
于 2016-09-19T15:35:04.490 回答