Java Json union(JsonObject... values)

Here you can find the source of union(JsonObject... values)

Description

Merges (unions) a list of Json objects into one object.

License

Apache License

Parameter

Parameter Description
values an array of Json objects.

Return

the merged object.

Declaration

public static JsonObject union(JsonObject... values) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2015, 2016 Junichi Tatemura
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.//from   ww w  .j  a v a 2s  .co m
 *******************************************************************************/

import java.util.Map;
import javax.json.Json;

import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;

import javax.json.JsonValue;

public class Main {
    /**
     * Merges (unions) a list of Json objects into one object.
     * @param values an array of Json objects.
     * @return the merged object.
     */
    public static JsonObject union(JsonObject... values) {
        JsonObjectBuilder builder = Json.createObjectBuilder();
        for (JsonObject v : values) {
            for (Map.Entry<String, JsonValue> e : v.entrySet()) {
                builder.add(e.getKey(), e.getValue());
            }
        }
        return builder.build();
    }
}

Related

  1. read(String jsonString)
  2. readMandatoryDateField(JsonParser jsonParser, String fieldName)
  3. requiredParams(JsonObject map, String... params)
  4. toDouble(Object input)
  5. toJsonArrayString(Iterator items)
  6. writeMandatoryDateField(JsonGenerator generator, String fieldName, Date value)
  7. writeReferenceValue(JsonGenerator generator, Integer value)