Spring Data Couchbase:如何重命名嵌套 POJO 中的字段?
Spring Data Couchbase: How to rename fields from nested POJOs?
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;
}
}
要具体回答您的问题,您可以在 Address
.
中使用 @Field("line1")
for street
我的项目中有类似的东西,它工作正常(参见 descriptions
)
Class 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;
}
Class 2
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Descriptions {
@Field("hotel_information") @JsonProperty("hotel_information")
public String hotelInformation;
}
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;
}
}
要具体回答您的问题,您可以在 Address
.
@Field("line1")
for street
我的项目中有类似的东西,它工作正常(参见 descriptions
)
Class 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;
}
Class 2
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Descriptions {
@Field("hotel_information") @JsonProperty("hotel_information")
public String hotelInformation;
}