我的代码中有一个 mongo 数据库调用。来自数据库的响应使用 codehaus jackson 进行映射。
杰森:
[
{
"_id": "555",
"rates": 1,
"reviews": [
{
"author_name": "Instructor 9999",
"_authKey": "demo\\556",
"text": "asdfa",
"date": 551,
"_id": "5454-4920",
"title": "asdf",
"comments": []
}
],
"votedUsers": [
{
"mng\\39999": 4
}
],
"rating": 4
},
{
"_id": "45589",
"rates": 1,
"reviews": [
{
"author_name": "feef",
"_authKey": "ad\\ads",
"text": "Working perfect",
"date": 1498659163,
"_id": "asdas-319",
"title": "test",
"comments": []
}
],
"votedUsers": [
{
"abc\\bis@cdf.com": 4
}
],
"rating": 4
}
]
我创建了以下 DTO 结构:
@JsonIgnoreProperties(ignoreUnknown = true)
public class MaterialReviewsDTO implements Serializable {
private static final long serialVersionUID = 1L;
private String _id;
private int rates;
private List<ReviewsDTO> reviews;
private List<VotedUsersDTO> votedUsers;
//List<TypeReference<HashMap<String, String>>> votedUsers;
private int rating;.
//Getter Setter
}
@JsonIgnoreProperties(ignoreUnknown = true)
public class VotedUsersDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Map<String, String> votedUser;
//Getter Setter
}
下面是我触发查询的代码:
List<MaterialReviewsDTO> materialReviewsDTOs = DBConnectionRealmByDBName
.find(query,
MaterialReviewsDTO.class,
CollectionNameConstant.REVIEWS_COLLECTION);
问题是除了以下部分之外,所有 JSON 都在 DTO 中映射:
"votedUsers" : [
{
"abc\\bis@cdf.com" : 4
}
]
VotedUserDTO 响应为空。VotedUsers 是包含键值对中数据的对象列表。
我没有提到ReviewsDTO,因为它被完美地映射了。我怎样才能映射votedUsers
部分?
注意:我正在使用 Spring 进行开发。