如何使用Jackson将一个ObjectNode作为子级添加到另一个ObjectNode中? [英] How to add an ObjectNode into another ObjectNode as a child using Jackson?

查看:717
本文介绍了如何使用Jackson将一个ObjectNode作为子级添加到另一个ObjectNode中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的ObjectNode.

I have the below ObjectNode.

handlerObjectNode -> {"Info":{"Brand":{"BrandName":"TOP OF THE WORLD"}}}

我还有另一个ObjectNode,格式如下.

I have another ObjectNode in the following format.

fieldObjects -> {"Description":"REGULAR BR"}

如何从以上两个创建下面的ObjectNode?

How can I create the below ObjectNode from the above two?

{
   "Info": {
       "Brand": {
           "BrandName": "TOP OF THE WORLD"
       }
   "Description": "REGULAR BR"
   }
 }

我尝试了以下代码.

handlerObjectNode.setAll(fieldObjects);

但是会导致以下ObjectNode.

But it results in the following ObjectNode.

{
   "Info": {
       "Brand": {
           "BrandName": "TOP OF THE WORLD"
       }
   },
   "Description": "REGULAR BR"
 }

我正在使用Jackson的com.fasterxml.jackson.databind.node.ObjectNode.任何帮助将不胜感激.

I am using the com.fasterxml.jackson.databind.node.ObjectNode from Jackson. Any help would be much appreciated.

推荐答案

尝试一下,

  root.with("Info").put("Description", "REGULAR BR");

有关更多信息,

这篇关于如何使用Jackson将一个ObjectNode作为子级添加到另一个ObjectNode中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆