Versions Compared

Key

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

...

POC: Replacing Jackson with Gson - tianl

I have investigated the feasibility of replacing all Jackson Spring Boot dependencies with Gson, by converting the two AAF security microservices, aaf-fproxy and aaf-rproxy to use Gson only.

The basic method I followed is detailed here: https://www.callicoder.com/configuring-spring-boot-to-use-gson-instead-of-jackson/

What I did:

  • Exclude all transitive Jackson dependencies being pulled in from the Spring Boot dependencies.
    • Exclude spring-boot-starter-json from spring-boot-starter-web
    • Remove any spring-boot-starter-actuator dependencies, as they can only work with Jackson.
  • Add a dependency to Gson (2.8.5), if one does not exist already.

At this point, if the application is only using Jackson for automatically serializing and deserializing request and response objects in its REST APIs, the conversion should be complete. Your Spring Boot application should now be switched to using the Gson implementation, and function as before.

Notes:

  • I did not need to add the "preferred-json-mapper" property to my application.properties as stated in the link above. Spring Boot 2.0.3 seems to be capable of detecting and using the Gson dependencies on its classpath automatically.
  • Additional complications and code changes may arise if you are explicitly using any of the Jackson library classes in your code. These will need to be manually converted to use the equivalent Gson classes instead.
  • Jackson dependencies may be pulled in transitively from other AAI modules (such as aai-common). Excluding these manually in your own pom may be risky, so ideally they need to be fixed at the source.