[英]Mongodb PojoCodec Found property not present in the ClassModel: id
Be me, perform aggregate query on MongoDb:做我,对MongoDb进行聚合查询:
db.Rubrica.aggregate([
{$match: {"fiscalCode": "asfjhsdfhgsdfugsdf"}},
{$project: {
"_id":0,
"contactsHeaders":"$contacts.header",
}}
]);
Get the result:得到结果:
{
"contactsHeaders" : [
{
"id" : "7b47c1637cde49d182b96bcc33d21d0d",
"alias" : "VOL LISTA",
"type" : "L"
},
{
"id" : "ab31c06ecce244bea4ab5b45b89f4fdc",
"alias" : "VOL FEDRO",
"type" : "S"
}
]
}
Now in Java i try to deserialize the Document in:现在在 Java 我尝试反序列化文档:
public class ListOfHeadersWrapper implements Serializable {
List<Header> contactsHeaders;
....
....
public class Header implements Serializable {
private String id;
private String alias;
private TypeEnum type;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
....
....
What I get is:我得到的是:
{
"contacts": [
{
"id": null,
"alias": "VOL LISTA",
"type": "L"
},
{
"id": null,
"alias": "VOL FEDRO",
"type": "S"
}
]
}
id is always null . id始终为null 。 Logs says Found property not present in the ClassModel: id .
日志显示 ClassModel: id 中不存在 Found 属性。
If I deserialize the thing manually with Jackson:如果我使用 Jackson 手动反序列化:
(new ObjectMapper()).readValue(res.toJson(), ListOfHeadersWrapper.class).toString()
I get the correct result:我得到正确的结果:
ListOfHeadersWrapper{contactsHeaders=[Header{id='7b47c1637cde49d182b96bcc33d21d0d', alias='VOL
WHY????为什么????
Adding @BsonProperty("id") does the trick:添加@BsonProperty("id")可以解决问题:
public class Header implements Serializable {
@BsonProperty("id")
private String id;
...
...
MongoDb sucks!!!! MongoDb 糟透了!!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.