Gets an object from an object for the given key. If the key is not present, this returns null. If the value is not a Map, throws an exception.
(Map<String, ?> obj, String key)
| 81 | * If the value is not a Map, throws an exception. |
| 82 | */ |
| 83 | @SuppressWarnings("unchecked") |
| 84 | @Nullable |
| 85 | public static Map<String, ?> getObject(Map<String, ?> obj, String key) { |
| 86 | assert key != null; |
| 87 | if (!obj.containsKey(key)) { |
| 88 | return null; |
| 89 | } |
| 90 | Object value = obj.get(key); |
| 91 | if (!(value instanceof Map)) { |
| 92 | throw new ClassCastException( |
| 93 | String.format("value '%s' for key '%s' in '%s' is not object", value, key, obj)); |
| 94 | } |
| 95 | return (Map<String, ?>) value; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Gets a number from an object for the given key. If the key is not present, this returns null. |