File tree Expand file tree Collapse file tree
src/main/java/io/github/hikingc/matrixsdk/services/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,10 +44,13 @@ private static ObjectMapper buildMapper() {
4444 public static String getStringValueOfAJsonKey (String json , String key ) {
4545 JsonNode tree = INSTANCE .readTree (json );
4646 if (tree == null || tree .isMissingNode ()) {
47+ throw new MatrixIOException ("Empty or malformed server response" );
48+ }
49+ JsonNode value = tree .get (key );
50+ if (value == null ) {
4751 throw new MatrixIOException ("Missing '%s' in server response" .formatted (key ));
4852 }
49-
50- return tree .get (key ).stringValue ();
53+ return value .asString ();
5154 }
5255
5356 /// Attempts to extract a key value from a deserialized JSON Object to a [List]. Useful for
@@ -58,7 +61,8 @@ public static String getStringValueOfAJsonKey(String json, String key) {
5861 /// @param elementType the [Class] to deserialize each element into.
5962 /// @param <T> the type to deserialize each element into
6063 /// @return the deserialized [List] of values for the given key
61- /// @throws MatrixIOException when the key was not in the response or the key value was not an Array
64+ /// @throws MatrixIOException when the key was not in the response or the key value was not an
65+ /// Array
6266 public static <T > List <T > getListFromAJsonKey (String json , String key , Class <T > elementType ) {
6367 JsonNode tree = INSTANCE .readTree (json );
6468 JsonNode value = tree .get (key );
You can’t perform that action at this time.
0 commit comments