JavaxJson { public static @NotNull JsonObject shallowMergeObjects(final @Nullable JsonObject base, final @Nullable JsonObject overlay) { JsonObjectBuilder init = Json.createObjectBuilder(); ofNullable(base).ifPresent(json -> json.forEach(init::add)); ofNullable(overlay).ifPresent(json -> json.forEach(init::add)); return init.build(); } 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 testShallowMergeObjects() { assertEquals("expect empty object from nulls", JsonObject.EMPTY_JSON_OBJECT, JavaxJson.shallowMergeObjects(null, null)); assertEquals("expect empty object from null and empty", JsonObject.EMPTY_JSON_OBJECT, JavaxJson.shallowMergeObjects(null, JsonValue.EMPTY_JSON_OBJECT)); assertEquals("expect empty object from empty and null", JsonObject.EMPTY_JSON_OBJECT, JavaxJson.shallowMergeObjects(JsonValue.EMPTY_JSON_OBJECT, null)); final JsonObject base = obj() .key("baseKey", "unmodified") .key("keyString", "base") .key("keyObject", key("baseKey", "unmodified").key("keyString", "base")) .get(); assertEquals("expect equal base for null overlay", base, shallowMergeObjects(base, null)); assertEquals("expect equal base for empty overlay", base, shallowMergeObjects(base, JsonValue.EMPTY_JSON_OBJECT)); assertEquals("expect equal base as overlay with null base", base, shallowMergeObjects(null, base)); assertEquals("expect equal base as overlay with empty base", base, shallowMergeObjects(JsonValue.EMPTY_JSON_OBJECT, base)); final JsonObject overlay = obj() .key("overlayKey", "unmodified") .key("keyString", "overlay") .key("keyObject", key("overlayKey", "unmodified").key("keyString", "overlay")) .get(); assertEquals("expect merged base <- overlay", obj() .key("baseKey", "unmodified") .key("overlayKey", "unmodified") .key("keyString", "overlay") .key("keyObject", key("overlayKey", "unmodified").key("keyString", "overlay")) .get(), shallowMergeObjects(base, overlay)); assertEquals("expect merged overlay <- base", obj() .key("baseKey", "unmodified") .key("overlayKey", "unmodified") .key("keyString", "base") .key("keyObject", key("baseKey", "unmodified").key("keyString", "base")) .get(), shallowMergeObjects(overlay, base)); }