10

How to generate an empty json node using jackson-java. I tried with NullNode.instance, but that returns

"totals":null

Whereas I want totals to be an empty instance.

{
  "totals": {},
  "orderId": "550047004",
  "numberOfItems": 2
}
Vikash
  • 2,046
  • 3
  • 23
  • 30
  • Possible duplicate of [how to create insert new nodes in JsonNode?](https://stackoverflow.com/questions/11503604/how-to-create-insert-new-nodes-in-jsonnode) – GolamMazid Sajib Jul 21 '18 at 12:58

1 Answers1

23

You should use ObjectNode. It can be created with ObjectMapper:

ObjectNode node = mapper.createObjectNode();
cassiomolin
  • 124,154
  • 35
  • 280
  • 359
  • 2
    Thanks! Just now I tried , new ObjectNode(JsonNodeFactory.instance), and got your answer too (quick) :) . – Vikash Jul 21 '18 at 12:54