如何将 CouchDB 文档上的属性映射到 java 模型对象?
我在 CouchDB 的数据库中有一组文档,其结构如下:
{
"_id": "adebafb022857385a4c970b0f0000349",
"_rev": "2-19d78f4d8d6386bfbe7b2c03b5213830",
"street_number": "20",
"street_name": "B.Baker St",
"city_name": "Marylebone",
"zip_code": "2550",
"status": "active"
}
如您所见,属性不是驼峰式大小写的,我尝试使用 JsonProperty 进行映射,但是,我在所有属性中都得到空值,除了对于状态属性。
我已将代码推送到此存储库中链接
非常感谢任何帮助
关于 CouchDB,我使用带有 CouchDB 映像的 docker 容器。
I have within a database a set of documents in CouchDB where their structure is as follow :
{
"_id": "adebafb022857385a4c970b0f0000349",
"_rev": "2-19d78f4d8d6386bfbe7b2c03b5213830",
"street_number": "20",
"street_name": "B.Baker St",
"city_name": "Marylebone",
"zip_code": "2550",
"status": "active"
}
as you can see the properties are not camel-cased, I have tried to make the mapping using JsonProperty, however, I get null value in all properties except for status property.
I have pushed the code in this repo link
Any help is much appreciated
Regarding the CouchDB, I using a docker container with CouchDB image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设这与 https://github.com/cloudant/java-cloudant/ 相同issues/536 值未正确反序列化,因为
JsonProperty
是 Jackson 注释,但库正在使用 Gson反序列化。Gson 等效注释是
@SerializedName
。Assuming this is the same as https://github.com/cloudant/java-cloudant/issues/536 the values are not deserialized correctly because
JsonProperty
is a Jackson annotation, but the library is using Gson deserialization.The Gson equivalent annotation is
@SerializedName
.我已将
com.google.code.gson
依赖项与@SerializedName
一起使用,如下所示:I have used
com.google.code.gson
dependency with@SerializedName
as follows: