Skip to content

Conversation

Avery-Dunn
Copy link
Contributor

Replace final usages of com.fasterxml.jackson with com.azure.json, as per #909

This PR makes changes to a lot of files, as they were unfortunately very interconnected and could not be split up into to multiple PRs like previous dependency removals.

However, most of the files received the same set of changes:

  • Adjust classes to implement azure-json's JsonSerializable interface, mainly by adding two methods:
    • toJson(), which creates a JsonWriter that can be used to create a JSON-formatted String
    • fromJson(), which creates an instance of that class from a JsonReader (which is give a JSON-formatted string)
  • Remove jackson-databind's JSON annotations from those classes

The following files are the exception, and have more bespoke changes that need a more thorough review:

  • JsonHelper: Received new methods and refactoring in order to better provide JSON helper methods to the rest of the codebase
  • TokenCache: Complete overhaul of the serialization/deserialization code

Finally, there were a few files that only received small changes to use the new JsonHelper methods.

For testing, many integration tests deal with the cache and received some small changes to work with the new helper methods and exact serialization results, and new unit tests were added to CacheTests specifically to ensure the serialization/deserialization changes in TokenCache were covered

  • One issue that became clear during this refactoring is that some tests used junk data in their persistent caches which was not used in anyway by the library (i.e., random field names), but was nonetheless added to the in-memory cache. Under the new system this type of junk data is no longer added to the in-memory cache, however this should not be a breaking change since the library would not have used it anyway

@Avery-Dunn Avery-Dunn requested a review from a team as a code owner May 7, 2025 01:39
@Avery-Dunn Avery-Dunn requested a review from Copilot May 7, 2025 17:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the remaining usages of com.fasterxml.jackson with com.azure.json by updating serialization and deserialization logic for core cache and token classes. Key changes include:

  • Implementing azure-json’s JsonSerializable interface in multiple classes
  • Refactoring all JSON read/write methods and adapting helper methods and tests accordingly

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
AuthorizationRequestUrlParametersTest.java Updated expected JSON string for "claims" parameter
TokenCache.java Refactored JSON deserialization/serialization and cache merge logic
RefreshTokenCacheEntity.java, IdTokenCacheEntity.java, etc. Updated serialization/deserialization methods to use azure.json
ClientInfo.java, Credential.java, AccountCacheEntity.java, etc. Replaced Jackson annotations with Azure JSON patterns
CachePersistenceIT.java Adjusted test assertions to match new cache token counts

if (jsonNode != null && jsonNode.isObject()) {
mergeJSONNode(jsonNode, addNode.get(fieldName));
if (mainMap.containsKey(key) && mainMap.get(key) instanceof Map && value instanceof Map) {
mergeJsonMaps((Map<String, Object>) mainMap.get(key), (Map<String, Object>) value);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all the inputs to this function controlled? Could malformed / malicious json be a problem here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the recursive call, mergeJsonMaps is only used in the mergeJSONString, which converts the two json strings to a map using JsonReader so I don't think malformed json would be an issue.

Malicious json could be, as this is used for claims and client capabilities, which are ultimately strings that come from the customer. However, the values in those jsons aren't something we can control or really verify, so I don't think there's much more we can do beyond JsonReader's parsing.

@Avery-Dunn Avery-Dunn merged commit 90d1a9e into avdunn/json-removal May 8, 2025
3 checks passed
@Avery-Dunn Avery-Dunn deleted the avdunn/json-cache-entities branch June 3, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants