Infra JsonUtil does not have replacement methods for deprecated JSONHelper?

I'm doing some work to deserialize a json payload using the infrastructure util jar (infra-util-21.2.0). This has two classes: JSONHelper.class and JsonUtil.class. JSONHelper has been marked deprecated and replaced by JsonUtil however JsonUtil does not have all the methods defined to fully replace JSONHelper. Can the deprecation for this be removed or the methods defined?

Best Answer

  • I believe
    com.trgr.cobalt.infrastructure.util.JsonUtil.fromJson(String, TypeReference ) replaces both
    com.trgr.cobalt.infrastructure.util.JSONHelper.fromJsonMap(String, TypeReference , Module...) and
    com.trgr.cobalt.infrastructure.util.JSONHelper.fromJsonList(String, TypeReference , Module...).

Answers

  • Thanks! You're right, this works for the list perfectly :) JsonUtil util = new JsonUtil(); return util.fromJson(response.getResponseDataAsString(), new TypeReference


    >() { });
  • Note that I would be careful using JsonUtil... it doesn't reuse `ObjectMapper` instances by default, which can definitely cause some overhead in systems which do a lot of JSON serialization/deserialization.
  • Note, however, that JSONHelper always creates a new ObjectMapper instance with each method call, so it will always have more overhead than JsonUtil. Recommended usage is to reuse an instance of JsonUtil, to eliminate the overhead of recreating the ObjectMapper with every call.
  • Good point Ryan. Reusing a JsonUtil instance or passing in a global ObjectMapper you manage yourself is optimal.