@Test public void testUnwrap() { assertNull("null unwrap to null", unwrap(null)); assertNull("JsonObject.NULL unwrap to null", unwrap(JsonObject.NULL)); assertEquals("JsonString unwrap to string", "foo", unwrap(wrap("foo"))); assertEquals("JsonNumber unwrap to number", 100L, unwrap(wrap(100))); List<String> ordinals = Arrays.asList("one", "two", "three"); assertEquals("unwrap a jsonarray to a List of objects", ordinals, unwrap(Json.createArrayBuilder().add("one").add("two").add("three").build())); Map<String, Object> someMap = Collections.singletonMap("foo", 5L); assertEquals("unwrap a jsonobject to a Map of String to Object", someMap, unwrap(Json.createObjectBuilder().add("foo", 5L).build())); assertTrue("unwrap JsonObject.TRUE to true", Optional.ofNullable(unwrap(JsonObject.TRUE)).map(Boolean.class::cast).orElse(false)); assertFalse("unwrap JsonObject.FALSE to false", Optional.ofNullable(unwrap(JsonObject.FALSE)).map(Boolean.class::cast).orElse(true)); }
@SuppressWarnings("WeakerAccess") public static Object unwrap(final JsonValue jsonValue) { if (jsonValue == null) { return null; } else { switch (jsonValue.getValueType()) { case STRING: return ((JsonString) jsonValue).getString(); case NUMBER: return ((JsonNumber) jsonValue).numberValue(); case NULL: return null; case ARRAY: return unwrapArray(jsonValue.asJsonArray()); case OBJECT: return unwrapObject(jsonValue.asJsonObject()); default: return jsonValue == JsonValue.TRUE; } } }
JavaxJson { @SuppressWarnings("WeakerAccess") public static Object unwrap(final JsonValue jsonValue) { if (jsonValue == null) { return null; } else { switch (jsonValue.getValueType()) { case STRING: return ((JsonString) jsonValue).getString(); case NUMBER: return ((JsonNumber) jsonValue).numberValue(); case NULL: return null; case ARRAY: return unwrapArray(jsonValue.asJsonArray()); case OBJECT: return unwrapObject(jsonValue.asJsonObject()); default: return jsonValue == JsonValue.TRUE; } } } }
JavaxJson { @SuppressWarnings("WeakerAccess") public static Object unwrap(final JsonValue jsonValue) { if (jsonValue == null) { return null; } else { switch (jsonValue.getValueType()) { case STRING: return ((JsonString) jsonValue).getString(); case NUMBER: return ((JsonNumber) jsonValue).numberValue(); case NULL: return null; case ARRAY: return unwrapArray(jsonValue.asJsonArray()); case OBJECT: return unwrapObject(jsonValue.asJsonObject()); default: return jsonValue == JsonValue.TRUE; } } } private  JavaxJson(); }
JavaxJson { @SuppressWarnings("WeakerAccess") public static Object unwrap(final JsonValue jsonValue) { if (jsonValue == null) { return null; } else { switch (jsonValue.getValueType()) { case STRING: return ((JsonString) jsonValue).getString(); case NUMBER: return ((JsonNumber) jsonValue).numberValue(); case NULL: return null; case ARRAY: return unwrapArray(jsonValue.asJsonArray()); case OBJECT: return unwrapObject(jsonValue.asJsonObject()); default: return jsonValue == JsonValue.TRUE; } } } private  JavaxJson(); static boolean nonEmptyValue(final @Nullable JsonValue value); static boolean nonDefaultValue(final @Nullable JsonValue value, final @NotNull JsonValue defaultValue); static JsonValue wrap(final Object object); @SuppressWarnings("WeakerAccess") static Object unwrap(final JsonValue jsonValue); @SuppressWarnings("WeakerAccess") static Map<String, Object> unwrapObject(final JsonObject jsonObject); @SuppressWarnings("WeakerAccess") static List<Object> unwrapArray(final JsonArray jsonArray); static @NotNull JsonObject shallowMergeObjects(final @Nullable JsonObject base,
                                                          final @Nullable JsonObject overlay); static Value val(Object value); static Obj obj(final Key... keys); static Obj obj(final JsonObject jsonObject); static Obj obj(final Map<?, ?> map); static Key key(final String key, final Object value); static KeyCursor key(final String key); static Arr arr(Object... values); @SuppressWarnings("WeakerAccess") static Optional<JsonObject> optObject(final JsonObject json, final String key); @SuppressWarnings("WeakerAccess") static JsonObject objectOrEmpty(final JsonObject json, final String key); @SuppressWarnings("WeakerAccess") static Optional<JsonArray> optArray(final JsonObject json, final String key); static JsonArray arrayOrEmpty(final JsonObject json, final String key); static List<String> mapArrayOfStrings(final JsonArray jsonArray); static List<R> mapArrayOfStrings(final JsonArray jsonArray,
                                                final Function<String, R> mapFunction); static List<R> mapArrayOfStrings(final JsonArray jsonArray,
                                                final Function<String, R> mapFunction,
                                                final boolean discardNulls); static List<R> mapArrayOfObjects(final JsonArray jsonArray,
                                                final Function<JsonObject, R> mapFunction); static List<R> mapArrayOfObjects(final JsonArray jsonArray,
                                                final Function<JsonObject, R> mapFunction,
                                                final boolean discardNulls); static List<R> mapObjectValues(final JsonObject jsonObject,
                                              final BiFunction<String, JsonObject, R> mapBiFunction,
                                              final boolean discardNulls); @SuppressWarnings("WeakerAccess") static List<R> parseFromArray(final @NotNull JsonArray jsonArray,
                                             final @NotNull Fun.ThrowingFunction<String, R> parser,
                                             final @Nullable BiConsumer<String, Exception> errorConsumer); static boolean hasNonNull(final @NotNull JsonObject json, final String key); }
JavaxJson { @SuppressWarnings("WeakerAccess") public static Object unwrap(final JsonValue jsonValue) { if (jsonValue == null) { return null; } else { switch (jsonValue.getValueType()) { case STRING: return ((JsonString) jsonValue).getString(); case NUMBER: return ((JsonNumber) jsonValue).numberValue(); case NULL: return null; case ARRAY: return unwrapArray(jsonValue.asJsonArray()); case OBJECT: return unwrapObject(jsonValue.asJsonObject()); default: return jsonValue == JsonValue.TRUE; } } } private  JavaxJson(); static boolean nonEmptyValue(final @Nullable JsonValue value); static boolean nonDefaultValue(final @Nullable JsonValue value, final @NotNull JsonValue defaultValue); static JsonValue wrap(final Object object); @SuppressWarnings("WeakerAccess") static Object unwrap(final JsonValue jsonValue); @SuppressWarnings("WeakerAccess") static Map<String, Object> unwrapObject(final JsonObject jsonObject); @SuppressWarnings("WeakerAccess") static List<Object> unwrapArray(final JsonArray jsonArray); static @NotNull JsonObject shallowMergeObjects(final @Nullable JsonObject base,
                                                          final @Nullable JsonObject overlay); static Value val(Object value); static Obj obj(final Key... keys); static Obj obj(final JsonObject jsonObject); static Obj obj(final Map<?, ?> map); static Key key(final String key, final Object value); static KeyCursor key(final String key); static Arr arr(Object... values); @SuppressWarnings("WeakerAccess") static Optional<JsonObject> optObject(final JsonObject json, final String key); @SuppressWarnings("WeakerAccess") static JsonObject objectOrEmpty(final JsonObject json, final String key); @SuppressWarnings("WeakerAccess") static Optional<JsonArray> optArray(final JsonObject json, final String key); static JsonArray arrayOrEmpty(final JsonObject json, final String key); static List<String> mapArrayOfStrings(final JsonArray jsonArray); static List<R> mapArrayOfStrings(final JsonArray jsonArray,
                                                final Function<String, R> mapFunction); static List<R> mapArrayOfStrings(final JsonArray jsonArray,
                                                final Function<String, R> mapFunction,
                                                final boolean discardNulls); static List<R> mapArrayOfObjects(final JsonArray jsonArray,
                                                final Function<JsonObject, R> mapFunction); static List<R> mapArrayOfObjects(final JsonArray jsonArray,
                                                final Function<JsonObject, R> mapFunction,
                                                final boolean discardNulls); static List<R> mapObjectValues(final JsonObject jsonObject,
                                              final BiFunction<String, JsonObject, R> mapBiFunction,
                                              final boolean discardNulls); @SuppressWarnings("WeakerAccess") static List<R> parseFromArray(final @NotNull JsonArray jsonArray,
                                             final @NotNull Fun.ThrowingFunction<String, R> parser,
                                             final @Nullable BiConsumer<String, Exception> errorConsumer); static boolean hasNonNull(final @NotNull JsonObject json, final String key); @SuppressWarnings("WeakerAccess")
    static final Function<JsonValue, String> JSON_VALUE_STRING; }