Java Json writeReferenceValue(JsonGenerator generator, Integer value)

Here you can find the source of writeReferenceValue(JsonGenerator generator, Integer value)

Description

Write a reference value (integer or null) into a JsonArray.

License

Apache License

Parameter

Parameter Description
generator the Json Generator being used to create the Json array
value the value to be inserted

Declaration

public static void writeReferenceValue(JsonGenerator generator, Integer value) 

Method Source Code

//package com.java2s;
/*/*from w  w  w .  j  a v  a  2s. co m*/
 * Copyright 2015-2017 Richard Linsdale.
 *
 * 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.
 */

import javax.json.JsonValue;

import javax.json.stream.JsonGenerator;

public class Main {
    /**
     * Write a reference value (integer or null) into a JsonObject.
     *
     * @param generator the Json Generator being used to create the Json object
     * @param key the key to be used
     * @param value the value to be used
     */
    public static void writeReferenceValue(JsonGenerator generator, String key, Integer value) {
        if (value == null) {
            generator.write(key, JsonValue.NULL);
        } else {
            generator.write(key, value);
        }
    }

    /**
     * Write a reference value (integer or null) into a JsonArray.
     *
     * @param generator the Json Generator being used to create the Json array
     * @param value the value to be inserted
     */
    public static void writeReferenceValue(JsonGenerator generator, Integer value) {
        if (value == null) {
            generator.write(JsonValue.NULL);
        } else {
            generator.write(value);
        }
    }
}

Related

  1. requiredParams(JsonObject map, String... params)
  2. toDouble(Object input)
  3. toJsonArrayString(Iterator items)
  4. union(JsonObject... values)
  5. writeMandatoryDateField(JsonGenerator generator, String fieldName, Date value)