Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Areas where Jackson is Used:

  1.    

...

  1. Direct usage of Jackson by Portal code
  2.    

...

  1. Indirect dependency through other packages
  2.     Frameworks configured with Jackson like Spring Boot


Modules with direct dependency on Jackson package:

...

  1. com.orbitz.consul:consul-client:jar - Excluded the jacskon dependency for this package and ran the build. The build is successful, however this needs to tested with real time scenarios.
  2. org.elasticsearch:elasticsearch:jar - Not using this package anywhere in the code and can be removed, as confirmed by Sunder
  3. Spring Boot

Code Analysis:

  1. Portal-SDK:   Approximately 60+ files that inculde fatserxml jackson excluding test files.
  2. Portal: Approximately 60+ files that inculde fatserxml jackson excluding test files

...

            Output for both methods, gson.fromJson() and mapper.readValue, is same


Replacing spring Boot Jackson dependencies with Gson:

         https://www.callicoder.com/configuring-spring-boot-to-use-gson-instead-of-jackson/

Jackson Methods used in our code and their equivalents in Gson:

            Below are few of the methods and their usages in Gson that can be used as replacements for Jackson,

Jackson MethodJackson ClassUsageGSON Equivalent MethodGSON Equivalent ClassUsage
readValuejackson.databind.ObjectMapper<ObjectType> obj = mapper.readValue(JsonString, ClassType);fromJsoncom.google.gson.Gson;<ObjectType> obj = gson.fromJson(data, RoleFunction.class);
writeValueAsStringjackson.databind.ObjectMapperString json = new ObjectMapper().writeValueAsString(Object);toJsoncom.google.gson.Gson;String resultJson = new Gson().toJson(Object);
configurejackson.databind.ObjectMapperobjectMapper.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
objectMapper.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
Use GsonBuilder to construct a Gson instance when you need to set configuration options other than the defaultcom.google.gson.GsonBuilderGson gson = new GsonBuilder()
     .serializeNulls()
     .setDateFormat(DateFormat.LONG)
     .create();
readTreejackson.databind.ObjectMapperJsonNode root = mapper.readTree(request.getReader());parsecom.google.gson.JsonParserJsonElement rootNode = parser.parse(jsonString);
NAjackson.databind.JsonNode;Base class for all JSON nodes, which form the basis of JSONNAimport com.google.gson.JsonElement;class representing an element of Json. It could either be a JsonObject, a JsonArray, a JsonPrimitive or a JsonNull
NAjackson.core.type.TypeReferenceTypeReference<List<Type>> typeRef = new TypeReference<List<Type>>() {};
      List<Type> listObj = mapper.readValue(requestBody, typeRef);
NAimport com.google.gson.reflect.TypeToken;listObj = gson.fromJson(jsonString, new TypeToken<Hashtable<String, Type>>() {}.getType());
NAimport com.fasterxml.jackson.databind.type.TypeFactory;
NA

NAjackson.annotation.JsonIgnoreProperties;JsonIgnoreProperties(ignoreUnknown = true)NAcom.google.gson.annotations.ExposeGSON @Expose annotation using GsonBuilder.excludeFieldsWithoutExposeAnnotation().
NAjackson.annotation.JsonRootName;JsonRootName(value="abc")
public class ClassName {}
NAjavax.xml.bind.annotation.XmlElementXmlRootElement
public class ClassName {}


References:
https://www.baeldung.com/jackson-vs-gson
http://websystique.com/java/json/gson-json-annotations-example/
https://www.tutorialspoint.com/gson/gson_tree_model.htm
https://google.github.io/gson/apidocs/index.html?com/google/gson/class-use/JsonElement.html
https://www.baeldung.com/gson-deserialization-guide
http://websystique.com/java/json/gson-tree-model-example/