Skip to content

Commit 62a4316

Browse files
author
Justin Richer
committed
added json member type checking for json utils, won't die if a string is found where an array was expected
closes mitreid-connect#637
1 parent 325a200 commit 62a4316

File tree

1 file changed

+12
-2
lines changed
  • openid-connect-common/src/main/java/org/mitre/discovery/util

1 file changed

+12
-2
lines changed

openid-connect-common/src/main/java/org/mitre/discovery/util/JsonUtils.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.List;
2525
import java.util.Set;
2626

27+
import com.google.common.collect.Lists;
28+
import com.google.common.collect.Sets;
2729
import com.google.gson.Gson;
2830
import com.google.gson.JsonElement;
2931
import com.google.gson.JsonObject;
@@ -141,7 +143,11 @@ public static Boolean getAsBoolean(JsonObject o, String member) {
141143
*/
142144
public static Set<String> getAsStringSet(JsonObject o, String member) throws JsonSyntaxException {
143145
if (o.has(member)) {
144-
return gson.fromJson(o.get(member), new TypeToken<Set<String>>(){}.getType());
146+
if (o.get(member).isJsonArray()) {
147+
return gson.fromJson(o.get(member), new TypeToken<Set<String>>(){}.getType());
148+
} else {
149+
return Sets.newHashSet(o.get(member).getAsString());
150+
}
145151
} else {
146152
return null;
147153
}
@@ -152,7 +158,11 @@ public static Set<String> getAsStringSet(JsonObject o, String member) throws Jso
152158
*/
153159
public static List<String> getAsStringList(JsonObject o, String member) throws JsonSyntaxException {
154160
if (o.has(member)) {
155-
return gson.fromJson(o.get(member), new TypeToken<List<String>>(){}.getType());
161+
if (o.get(member).isJsonArray()) {
162+
return gson.fromJson(o.get(member), new TypeToken<List<String>>(){}.getType());
163+
} else {
164+
return Lists.newArrayList(o.get(member).getAsString());
165+
}
156166
} else {
157167
return null;
158168
}

0 commit comments

Comments
 (0)