1414import com .fasterxml .jackson .databind .ObjectMapper ;
1515import com .fasterxml .jackson .databind .node .ObjectNode ;
1616import com .fasterxml .jackson .databind .JsonNode ;
17+ import org .slf4j .Logger ;
18+ import org .slf4j .LoggerFactory ;
1719
1820import java .io .IOException ;
1921import java .nio .charset .StandardCharsets ;
2022import java .util .*;
2123
2224class JsonHelper {
25+ private static final Logger LOG = LoggerFactory .getLogger (JsonHelper .class );
26+
2327 static ObjectMapper mapper ;
2428
2529 static {
@@ -36,6 +40,7 @@ static <T> T convertJsonToObject(final String json, final Class<T> tClass) {
3640 try {
3741 return mapper .readValue (json , tClass );
3842 } catch (Exception e ) {
43+ LOG .error (String .format ("Error converting JSON string into %s: %s" , tClass , e .getMessage ()));
3944 throw new MsalJsonParsingException (e .getMessage (), AuthenticationErrorCode .INVALID_JSON );
4045 }
4146 }
@@ -48,6 +53,7 @@ static String getTokenPayloadClaims(String token) {
4853 try {
4954 return new String (Base64 .getUrlDecoder ().decode (token .split ("\\ ." )[1 ]), StandardCharsets .UTF_8 );
5055 } catch (ArrayIndexOutOfBoundsException e ) {
56+ LOG .error ("Error parsing ID token, missing payload section." );
5157 throw new MsalClientException ("Error parsing ID token, missing payload section." ,
5258 AuthenticationErrorCode .INVALID_JWT );
5359 }
@@ -63,20 +69,11 @@ static Map<String, Object> parseJsonToMap(String jsonString) {
6369 jsonReader .nextToken ();
6470 return parseJsonObject (jsonReader );
6571 } catch (IOException e ) {
72+ LOG .error ("JSON parsing error when attempting to convert JSON into a Map." );
6673 throw new MsalJsonParsingException (e .getMessage (), AuthenticationErrorCode .INVALID_JSON );
6774 }
6875 }
6976
70- private static List <Object > parseJsonArray (JsonReader jsonReader ) throws IOException {
71- List <Object > array = new ArrayList <>();
72-
73- while (jsonReader .nextToken () != JsonToken .END_ARRAY ) {
74- array .add (parseValue (jsonReader ));
75- }
76-
77- return array ;
78- }
79-
8077 private static Map <String , Object > parseJsonObject (JsonReader jsonReader ) throws IOException {
8178 Map <String , Object > object = new HashMap <>();
8279
@@ -130,7 +127,7 @@ private static Object parseValue(JsonReader jsonReader) throws IOException {
130127 case NULL :
131128 return null ;
132129 case START_ARRAY :
133- return parseJsonArray ( jsonReader );
130+ return jsonReader . readArray ( JsonReader :: readUntyped );
134131 case START_OBJECT :
135132 return parseJsonObject (jsonReader );
136133 default :
0 commit comments