Skip to content

Commit 922a68d

Browse files
committed
Clean-up
1 parent 35ee765 commit 922a68d

File tree

3 files changed

+4
-18
lines changed

3 files changed

+4
-18
lines changed

library/src/main/java/com/mastercard/developer/oauth2/http/UserAgent.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,22 @@ public final class UserAgent {
1212
private static final String PRODUCT = "Mastercard-OAuth2-Client";
1313
private static final String UNKNOWN_VERSION = "0.0.0-unknown";
1414
private static final String VERSION = readVersionFile();
15-
// Cache the user-agent string to avoid rebuilding it on every call
16-
private static final String CACHED_USER_AGENT = buildUserAgent();
1715

1816
private UserAgent() {}
1917

2018
/**
21-
* Returns a stable, pre-built user-agent string:
19+
* Builds a stable user-agent string:
2220
* Product/Version (Runtime; OS [OS Version])
2321
* Example:
2422
* Mastercard-OAuth2-Client/1.0.0 (Java/17.0.2; Linux 5.15)
2523
*/
2624
public static String get() {
27-
return CACHED_USER_AGENT;
28-
}
29-
30-
private static String buildUserAgent() {
3125
String javaVer = System.getProperty("java.version", "unknown");
3226
String osName = System.getProperty("os.name", "unknown");
3327
String osVer = System.getProperty("os.version", "").trim();
3428
String runtime = "Java/" + javaVer;
3529
String osPart = osName + (osVer.isEmpty() ? "" : " " + osVer);
36-
return PRODUCT + "/" + VERSION + " (" + runtime + "; " + osPart + ")";
30+
return String.format("%s/%s (%s; %s)", PRODUCT, VERSION, runtime, osPart);
3731
}
3832

3933
private static String readVersionFile() {

library/src/main/java/com/mastercard/developer/oauth2/internal/json/GsonJsonProvider.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.mastercard.developer.oauth2.internal.json;
22

33
import com.google.gson.Gson;
4-
import com.google.gson.GsonBuilder;
54
import com.google.gson.reflect.TypeToken;
65
import com.mastercard.developer.oauth2.internal.json.exception.OAuth2ClientJsonException;
76
import java.lang.reflect.Type;
@@ -10,12 +9,7 @@
109

1110
public class GsonJsonProvider implements JsonProvider {
1211

13-
// Use a configured Gson instance and cache the Map type to avoid allocating a new TypeToken on each parse.
14-
private static final Gson gson = new GsonBuilder()
15-
.disableHtmlEscaping()
16-
.serializeNulls()
17-
.create();
18-
12+
private static final Gson gson = new Gson();
1913
private static final Type MAP_TYPE = new TypeToken<Map<String, Object>>() {}.getType();
2014

2115
@Override

library/src/main/java/com/mastercard/developer/oauth2/internal/json/JacksonJsonProvider.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
public class JacksonJsonProvider implements JsonProvider {
1010

1111
private static final ObjectMapper mapper = new ObjectMapper();
12-
13-
// Cache the TypeReference to avoid creating a new anonymous subclass on each parse call.
14-
private static final TypeReference<Map<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<Map<String, Object>>() {};
12+
private static final TypeReference<Map<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<>() {};
1513

1614
@Override
1715
public Map<String, Object> parse(String json) throws OAuth2ClientJsonException {

0 commit comments

Comments
 (0)