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

Bump com.google.code.gson:gson from 2.10.1 to 2.11.0 #135

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
dependencies {
implementation "com.squareup.retrofit2:retrofit:2.11.0"
api "com.squareup.retrofit2:converter-gson:2.11.0"
api 'com.google.code.gson:gson:2.10.1'
api 'com.google.code.gson:gson:2.11.0'
testImplementation "org.junit.jupiter:junit-jupiter:5.11.0"
testImplementation "org.mockito:mockito-core:5.13.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public class WikiConstants {
"Failed to load constants file %s: %s";
private static final Gson gson = new Gson();

private static final Set<String> BEHAVIOR_SWITCHES = readSetConstant("behavior_switches.json");
private static final Set<String> BEHAVIOR_SWITCHES =
readSetConstant("behavior_switches.json", String.class);
private static final Set<String> LANGUAGE_CODES =
readSetOfStringsConstantToLowercase("language_codes.json");
private static final Map<String, String> NAMESPACES = readMapConstant("namespaces.json");
private static final Map<String, String> NAMESPACES =
readMapConstant("namespaces.json", String.class, String.class);
private static final Set<String> WIKIS = readSetOfStringsConstantToLowercase("wikis.json");

public static boolean isBehaviorSwitch(String behaviorSwitch) {
Expand All @@ -39,27 +41,30 @@ public static boolean isWiki(String wiki) {
return WIKIS.contains(wiki.toLowerCase(Locale.ROOT));
}

private static <T, U> Map<T, U> readMapConstant(String filename) {
private static <K, V> Map<K, V> readMapConstant(
String filename, Class<K> keyClass, Class<V> valueClass) {
try {
String constantString = readStringConstant(filename);
return gson.fromJson(constantString, new TypeToken<Map<T, U>>() {}.getType());
TypeToken<Map<K, V>> token =
(TypeToken<Map<K, V>>) TypeToken.getParameterized(Map.class, keyClass, valueClass);
return gson.fromJson(constantString, token);
} catch (Exception e) {
throw new IllegalStateException(
String.format(CONSTANT_LOADING_ERROR_MESSAGE, filename, e.getMessage()));
}
}

private static Set<String> readSetOfStringsConstantToLowercase(String filename) {
return readSetConstant(filename).stream()
.map(String.class::cast)
return readSetConstant(filename, String.class).stream()
.map(String::toLowerCase)
.collect(Collectors.toSet());
}

private static <T> Set<T> readSetConstant(String filename) {
private static <T> Set<T> readSetConstant(String filename, Class<T> clazz) {
try {
String constantString = readStringConstant(filename);
return gson.fromJson(constantString, new TypeToken<Set<T>>() {}.getType());
TypeToken<Set<T>> token = (TypeToken<Set<T>>) TypeToken.getParameterized(Set.class, clazz);
return gson.fromJson(constantString, token);
} catch (Exception e) {
throw new IllegalStateException(
String.format(CONSTANT_LOADING_ERROR_MESSAGE, filename, e.getMessage()));
Expand Down