All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.json.JsonArrayBuilder Maven / Gradle / Ivy

There is a newer version: 1.1.4
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */

package javax.json;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * A builder for creating {@link JsonArray} models from scratch. This
 * interface initializes an empty JSON array model and provides methods to add
 * values to the array model and to return the resulting array. The methods
 * in this class can be chained to add multiple values to the array.
 *
 * 

The class {@link javax.json.Json} contains methods to create the builder * object. The example code below shows how to build an empty {@code JsonArray} * instance. *

 * 
 * JsonArray array = Json.createArrayBuilder().build();
 * 
 * 
* *

The class {@link JsonBuilderFactory} also contains methods to create * {@code JsonArrayBuilder} instances. A factory instance can be used to create * multiple builder instances with the same configuration. This the preferred * way to create multiple instances. * * * The example code below shows how to build a {@code JsonArray} object * that represents the following JSON array: * *

 * 
 * [
 *     { "type": "home", "number": "212 555-1234" },
 *     { "type": "fax", "number": "646 555-4567" }
 * ]
 * 
 * 
* *

The following code creates the JSON array above: * *

 * 
 * JsonBuilderFactory factory = Json.createBuilderFactory(config);
 * JsonArray value = factory.createArrayBuilder()
 *     .add(factory.createObjectBuilder()
 *         .add("type", "home")
 *         .add("number", "212 555-1234"))
 *     .add(factory.createObjectBuilder()
 *         .add("type", "fax")
 *         .add("number", "646 555-4567"))
 *     .build();
 * 
 * 
* *

This class does not allow null to be used as a * value while building the JSON array * * @see JsonObjectBuilder */ public interface JsonArrayBuilder { /** * Adds a value to the array. * * @param value the JSON value * @return this array builder * @throws NullPointerException if the specified value is null */ JsonArrayBuilder add(JsonValue value); /** * Adds a value to the array as a {@link JsonString}. * * @param value the string value * @return this array builder * @throws NullPointerException if the specified value is null */ JsonArrayBuilder add(String value); /** * Adds a value to the array as a {@link JsonNumber}. * * @param value the number value * @return this array builder * @throws NullPointerException if the specified value is null * * @see JsonNumber */ JsonArrayBuilder add(BigDecimal value); /** * Adds a value to the array as a {@link JsonNumber}. * * @param value the number value * @return this array builder * @throws NullPointerException if the specified value is null * * @see JsonNumber */ JsonArrayBuilder add(BigInteger value); /** * Adds a value to the array as a {@link JsonNumber}. * * @param value the number value * @return this array builder * * @see JsonNumber */ JsonArrayBuilder add(int value); /** * Adds a value to the array as a {@link JsonNumber}. * * @param value the number value * @return this array builder * * @see JsonNumber */ JsonArrayBuilder add(long value); /** * Adds a value to the array as a {@link JsonNumber}. * * @param value the number value * @return this array builder * @throws NumberFormatException if the value is Not-a-Number(NaN) or * infinity * * @see JsonNumber */ JsonArrayBuilder add(double value); /** * Adds a {@link JsonValue#TRUE} or {@link JsonValue#FALSE} value to the * array. * * @param value the boolean value * @return this array builder */ JsonArrayBuilder add(boolean value); /** * Adds a {@link JsonValue#NULL} value to the array. * * @return this array builder */ JsonArrayBuilder addNull(); /** * Adds a {@link JsonObject} from an object builder to the array. * * @param builder the object builder * @return this array builder * @throws NullPointerException if the specified builder is null */ JsonArrayBuilder add(JsonObjectBuilder builder); /** * Adds a {@link JsonArray} from an array builder to the array. * * @param builder the array builder * @return this array builder * @throws NullPointerException if the specified builder is null */ JsonArrayBuilder add(JsonArrayBuilder builder); /** * Returns the current array. * * @return the current JSON array */ JsonArray build(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy