JavaxJson { public static Obj obj(final Key... keys) { return new Obj(keys); } 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; }
@Test public void testObj() { JsonObject object = obj().get(); assertNotNull("obj().get() results in non-null JsonObject", object); assertTrue("obj().get() results in empty JsonObject", object.keySet().isEmpty()); JsonObject nullJSON = obj((JsonObject) null).get(); assertNotNull("obj((JsonObject) null).get() results in non-null JsonObject", nullJSON); assertTrue("obj((JsonObject) null).get() results in empty JsonObject", nullJSON.keySet().isEmpty()); JsonObject reJSON = obj(key("color", "red").get()).get(); assertEquals("JsonObject to obj to JsonObject", "red", reJSON.getString("color")); Map<String, Object> reMap = new HashMap<>(); reMap.put("color", "blue"); JsonObject reMapJSON = obj(reMap).get(); assertEquals("Map to obj to JsonObject", "blue", reMapJSON.getString("color")); assertEquals("obj deep equals obj(key, key) : obj().key(key, val).key(key2, val2)", obj(key("foo", "bar"), key("foo2", "bar2")).get(), obj().key("foo", "bar").key("foo2", "bar2").get()); assertEquals("obj deep equals obj(key, key) : obj(key(key, val)).and(key(key2, val2))", obj(key("foo", "bar"), key("foo2", "bar2")).get(), obj(key("foo", "bar")).and(key("foo2", "bar2")).get()); assertEquals("obj.arrKeys() retains order and duplicates", "[\"one\",\"two\",\"three\",\"two\"]", key("one", 1).key("two", 2).key("three", 3).key("two", -2).arrKeys().get().toString()); assertEquals("obj.arrVals() retains order and duplicates", "[1,2,3,-2]", key("one", 1).key("two", 2).key("three", 3).key("two", -2).arrVals().get().toString()); assertEquals("key(string).opt(null) should leave empty object", Json.createObjectBuilder().build(), obj().key("key").opt(null).get()); assertEquals("key(string).opt(null, ifNotValue) should return key and JsonObject.NULL when ifNotValue is provided", Json.createObjectBuilder().add("key", JsonValue.NULL).build(), obj().key("key").opt(null, "value").get()); assertEquals("key(string).opt(obj()) should leave empty object", Json.createObjectBuilder().build(), obj().key("key").opt(obj()).get()); assertEquals("key(string).opt(arr()) should leave empty object", Json.createObjectBuilder().build(), obj().key("key").opt(arr()).get()); assertEquals("key(string).opt(JsonObject.NULL) should leave empty object", Json.createObjectBuilder().build(), obj().key("key").opt(JsonObject.NULL).get()); assertEquals("key(string).opt(string) should return object with key", Json.createObjectBuilder().add("key", "value").build(), obj().key("key").opt("value").get()); assertEquals("key(string).opt(string, default) should return object with key", Json.createObjectBuilder().add("key", "value").build(), obj().key("key").opt("value", "notValue").get()); assertEquals("key(string).opt(string, ifNotValue) should return object with key when value is not ifNotValue", Json.createObjectBuilder().add("key", "value").build(), obj().key("key").opt("value", "notValue").get()); assertEquals("key(string).opt(string, ifNotValue) should return empty object when value is ifNotValue", Json.createObjectBuilder().build(), obj().key("key").opt("value", "value").get()); }