Faster XML Jackson usage in Portal Code and replacing it with Gson
Areas where Jackson is Used:
Direct usage of Jackson by Portal code
Indirect dependency through other packages
Frameworks configured with Jackson like Spring Boot
Modules with direct dependency on Jackson package:
Portal-SDK:
epsdk-fw
epsdk-analytics
epsdk-app-common
epsdk-app-os
epsdk-core
epsdk-domain
epsdk-music
epsdk-workflow
epsdk-aaf
Portal:
Portal-BE-Common:
Portal-BE-OS:
Portal-widget-ms:
Packages used that have dependency on Jackson:
Portal-SDK:
org.elasticsearch:elasticsearch:jar – Not using this package anywhere in the code and can be removed, as confirmed by Sunder.
org.onap.portal.sdk:epsdk-music:jar
Portal:
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.
org.elasticsearch:elasticsearch:jar - Not using this package anywhere in the code and can be removed, as confirmed by Sunder
Spring Boot
Code Analysis:
Portal-SDK: Approximately 60+ files that inculde fatserxml jackson excluding test files.
Portal: Approximately 60+ files that inculde fatserxml jackson excluding test files
Using Gson In our Code:
Gson Maven Dependency:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
POC- Replacing Jackson with Gson in our code:
Gson FromJson method as replacement for Jackson readValue method-Replaced Jackson methods with Gson methods in saveRoleFunction() method of RoleFunctionListController class as below,
Replaced this,
public void saveRoleFunction() {
String data = roleFunc;
RoleFunction availableRoleFunction = mapper.readValue(data, RoleFunction.class);
System.out.println("mapper.readVlaue:"+availableRoleFunction);
}
With this,
public void saveRoleFunction() {
String data = roleFunc;
RoleFunction roleFunctonAvailable = gson.fromJson(data, RoleFunction.class);
System.out.println("gson:fromJson:"+roleFunctonAvailable);
}
Output for both methods, gson.fromJson() and mapper.readValue, is same.
Gson toJson method as replacement for Jackson writeValueAsString method-Replaced Jackson methods with Gson methods in buildJsonResponse() method of JsonMessage class as below,
Replaced this,
public static String buildJsonResponse(boolean success, String msg) {
String json = null;
json = new ObjectMapper().writeValueAsString(response);
System.out.println("mapper.WriteValueAsString:"+json);
return json;
}
With this,
public static String buildJsonResponse(boolean success, String msg) {
String jsonFromGson = null;
jsonFromGson = new Gson().toJson(response);
System.out.println("Gson().toJson:"+jsonFromGson);
return jsonFromGson;
}
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,