Versions Compared

Key

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

...

FasterXML Jackson versionGoogle gson versionComments
Code Block
mapper = new ObjectMapper();
Code Block
JsonParser parser = new JsonParser();

Code Block
JsonNode rootNode = mapper.readTree(new File(authFilename));
JsonNode rolesNode = rootNode.path(AuthConstants.ROLES_NODE_PATH);
Code Block
JsonObject authObject = parser.parse(authFile).getAsJsonObject();
JsonArray roles = authObject.getAsJsonArray("roles");

Code Block
String function = functionNode.path(AuthConstants.FUNCTION_NAME_PATH).asText();
Code Block
String roleName = roleObject.get("name").getAsString();
Code structure differs at this point (function name vs role name) but the general intent of the code is equivalent (get the element name as a string).
Code Block
public synchronized void loadUsers(String authFilename) throws Exception


(no exception handling in this method)
Code Block
} catch (JsonProcessingException e) {
			ErrorLogHelper.logError("AAI_4001", globalAuthFileName + ". Not valid JSON: " + e);

For some reason, this version still catches com.fasterxml.jackson.core.JsonProcessingException even though it uses Google gson for parsing.

Not a good idea to defer exception handling to the caller since the caller has no idea why/how/when/where the parsing failed and might be left with an invalid data structure as well.

Code Block
boolean hasMethods = handleMethodNode(methodsNode, role, function);
Code Block
usrs.forEach((key, value) -> {
...
});
Method call vs Java lambda call is not really relevant to the Jackson replacement, but consistency of style could be an overall goal if the code is being re-factored anyway.

...