json 反序列化器到目标对象
您能否推荐一个可以反序列化为现有对象(合并 2 个对象)的 Json 反序列化器?
当用户提交表单时,我想以这种方式将其保存到数据库中:
这是来自客户端的 json:
{"affiliateId":1,"name":"First Affiliate","email":"[email protected]","user.userName":"test","user.password":"pass-hashed","employee.employeeId":1}
Affiliate affiliateFromDb = affiliateApi.getFromDbById(1);
SomeDeserialization json = new SomeDeserialization();
affiliateFromDb = json.fromJson(affiliateFromJson , affiliateFromDb );//affiliateFromDb = target bean
这意味着我希望将affiliateFromJson 插入到affiliateFromDb 中。
然后我会调用
affiliateApi.save(affiliateFromDb);
注意json包含深度反序列化,user.userName
谢谢
Can you recommend on a Json Deserializer that can deserialize into existing object (merge 2 objects)?
When the user submit a form I want to save that into the db this way:
this is the json from the client:
{"affiliateId":1,"name":"First Affiliate","email":"[email protected]","user.userName":"test","user.password":"pass-hashed","employee.employeeId":1}
Affiliate affiliateFromDb = affiliateApi.getFromDbById(1);
SomeDeserialization json = new SomeDeserialization();
affiliateFromDb = json.fromJson(affiliateFromJson , affiliateFromDb );//affiliateFromDb = target bean
Meaning that I want the affiliateFromJson to be interpolated into affiliateFromDb.
And than I will call
affiliateApi.save(affiliateFromDb);
Note that the json contains deep deserialize, user.userName
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Gson!特别是,请参阅对象示例。
这里唯一的问题是您想要使用的非标准“深度”对象格式,但您将使用任何其他 JSON(反)序列化器都会遇到同样的问题。你必须使用这样的东西来代替:
Use Gson! In particular, see the Object Examples.
The only catch here — but you will have this same problem with any other JSON (de)serializer — is the nonstandard "deep" object format you want to work with. You would have to use something like this instead:
http://www.json.org/javadoc/org/json/JSONObject.html
http://www.json.org/javadoc/org/json/JSONObject.html