Jackson ObjectMapper valueToTree method also write valueType and integral but no actual value

2.7k Views Asked by At

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.

0

There are 0 best solutions below