javax.json: Add new JsonNumber to existing JsonObject

后端 未结 3 1141
渐次进展
渐次进展 2020-12-31 02:59

I want to add properties to an existing instance of JsonObject. If this property is boolean, this is quite easy:

JsonObject jo = ..         


        
3条回答
  •  悲哀的现实
    2020-12-31 03:41

    Try using JsonPatch

    String json ="{\"name\":\"John\"}";
    JsonObject jo = Json.createReader(new StringReader(json)).readObject();
    JsonPatch path = Json.createPatchBuilder()
            .add("/last","Doe")
            .build();
    jo = path.apply(jo);
    System.out.println(jo);
    

提交回复
热议问题