I am trying to convert a JAVA POJO object with a JsonObject
to a String as following:
class MyPojo {
public MyPojo(String sName, JsonObject obj)
{
this.sName = sName;
this.tJsonObj = obj;
}
public String sName;
public javax.json.JsonObject tJsonObj;
};
javax.json.JsonObject jsonObj = JsonUtils.toJsonObject("{\\"key\\": 123}");
ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper.ObjectMapper();
JsonNode node = mapper.valueToTree(new MyPojo("myname", jsonObj));
String jsonStr = node.toString();
I am getting jsonStr
value as:
{"sName":"myname","tJsonObj":{"key":{"integral":true,"valueType":"NUMBER"}}}
How can I get jsonStr
value as:
{"sName":"myname","tJsonObj":{"key":123}}
JsonUtils.toJsonObject
is my own utility method to get JsonObject
from String
.