Java Json Create createJsonValue(String string)

Here you can find the source of createJsonValue(String string)

Description

Create a JsonValue using a String

License

Apache License

Parameter

Parameter Description
string the String

Return

the equivalent JsonValue

Declaration

public static JsonValue createJsonValue(String string) 

Method Source Code


//package com.java2s;
/*//ww w  .j  a v a  2 s  . com
 * 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.Json;

import javax.json.JsonValue;

public class Main {
    /**
     * Create a JsonValue using a String
     *
     * @param string the String
     * @return the equivalent JsonValue
     */
    public static JsonValue createJsonValue(String string) {
        return Json.createObjectBuilder().add("value", string).build().getJsonString("value");
    }

    /**
     * Create a JsonValue using an integer
     *
     * @param value the integer value
     * @return the equivalent JsonValue
     */
    public static JsonValue createJsonValue(int value) {
        return Json.createObjectBuilder().add("value", value).build().getJsonNumber("value");
    }
}

Related

  1. convertToJson(Object myObject)
  2. convertToJson(Object obj)
  3. createArrayBuilder()
  4. createArrayBuilder()
  5. createJsonFrom(JsonObject user, String... ignoreKeys)
  6. createPrettyWriterFactory()
  7. emptyArray()
  8. getJson(T t)
  9. object2JsonDateSerializer(Object obj, final String dateformat)