Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Replace deprecated constructor call and fix unchecked assignment warning #1000

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

MartinWheelerMT
Copy link
Collaborator

@MartinWheelerMT MartinWheelerMT commented Nov 20, 2024

What

  • Code Quality fix to replace deprecated constructors on URL(java.lang.String) with the recommended URI().toURL()` method instead
  • Fix warning with Unchecked assignment: 'java.util.HashMap' to 'java.util.Map<java.lang.String,java.lang.Object>'"

Why

Deprecate URL public constructors
Warning: Unchecked assignment: 'java.util.HashMap' to 'java.util.Map<java.lang.String,java.lang.Object>'

Type of change

Please delete options that are not relevant.

  • Internal change (non-breaking change with no effect on the functionality affecting end users)

Checklist:

  • I have performed a self-review of my code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

…ssignment warning

Code Quality fix to replace deprecated constructors on `URL(java.lang.String) with the recommended `URI().toURL()` method instead
Fix waring with "Warning:(42, 16) Unchecked assignment: 'java.util.HashMap' to 'java.util.Map<java.lang.String,java.lang.Object>'"
Copy link

Looks good. No mutations were possible for these changes.
See https://pitest.org

@@ -37,7 +38,7 @@ public Map<String, Object> patient(String nhsNumber) throws Exception {

String patientData = getPatientData(nhsNumber, accessToken);

return new ObjectMapper().readValue(patientData, HashMap.class);
return new ObjectMapper().readValue(patientData, new TypeReference<>() {});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The part which is new TypeReference<>() {} is actually new TypeReference<Map<String, Object>>() {} but you can omit the Map<String, Object>> if it can be inferred.

This is a way to provide full type information to Jackson when deserializing, avoiding unchecked warnings. It's a generic safe way to tell the object mapper what it is being deserialized into

@adrianclay adrianclay merged commit bf88ffd into main Nov 21, 2024
15 checks passed
@adrianclay adrianclay deleted the code-quality-depricated-url-constructors branch November 21, 2024 10:56
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.

2 participants