Java Json nullable(String value)

Here you can find the source of nullable(String value)

Description

Returns a JsonValue from a String.

License

Apache License

Parameter

Parameter Description
value Value

Return

JsonValue

Declaration

public static JsonValue nullable(String value) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.json.Json;
import javax.json.JsonValue;

public class Main {
    /**//from   ww  w .ja v a 2 s.  c  o m
     * Returns a JsonValue from a String.
     * 
     * @param value Value
     * @return JsonValue
     */
    public static JsonValue nullable(String value) {
        if (value == null) {
            return JsonValue.NULL;
        }
        return Json.createObjectBuilder().add("_", value).build().get("_");
    }

    /**
     * Returns a JsonValue from an Integer.
     * 
     * @param value Value
     * @return JsonValue
     */
    public static JsonValue nullable(Integer value) {
        if (value == null) {
            return JsonValue.NULL;
        }
        return Json.createObjectBuilder().add("_", value).build().get("_");
    }
}

Related

  1. jsonString(JsonValue value)
  2. jsonValueToJsonString(final JsonValue jsonValue, final String key)
  3. listToJsonArray(List list)
  4. mapToJsonObjectBuilder(Map map)
  5. newObject()
  6. objectToJsonDateSerializer(Object ts, final String dateformat)
  7. printJavaxJsonProvider()
  8. read(String jsonString)
  9. readMandatoryDateField(JsonParser jsonParser, String fieldName)