Updated on 2022-09-01 GMT+08:00

JsonUtils

Path

com.roma.apic.livedata.common.v1.JsonUtils

Description

This class is used to provide the conversion between JSON and objects and between JSON and XML.

Example

importClass(com.roma.apic.livedata.common.v1.JsonUtils);
function execute(data) {
    return JsonUtils.convertJsonToXml('{"a":1}')
}

Method List

Returned Type

Method and Description

static String

convertJsonToXml(String json)

Convert JSON into XML.

static String

convertJsonToXml(String json, String rootName)

Convert JSON into XML.

static <T> T

toBean(String json, Class<T> clazz)

Convert JSON into an object.

static String

toJson(Object object)

Convert an object to a character string in JSON format.

static String

toJson(Object object, Map<String,Object> config)

Convert an object to a character string in JSON format and use the configuration in the config file.

For example, you can set "date-format" in config to "yyyy-MM-dd HH:mm:ss".

static Map<String,Object>

toMap(String json)

Convert JSON into MAP.

Method Details

  • public static String convertJsonToXml(String json)

    Convert JSON into XML.

    Input Parameter

    json indicates a character string in JSON format.

    Returns

    Character string in XML format

  • public static String convertJsonToXml(String json, String rootName)

    Convert JSON into XML.

    Input Parameter

    • json indicates a character string in JSON format.
    • rootName indicates the root node name of the XML file.

    Returns

    Character string in XML format

  • public static <T> T toBean(String json, Class<T> clazz)

    Convert JSON into an object.

    Input Parameter

    • json indicates a character string in JSON format.
    • clazz indicates the class.

    Returns

    Class object.

  • public static String toJson(Object object)

    Convert an object to a character string in JSON format.

    Input Parameter

    object indicates an object.

    Returns

    Character string in JSON format obtained after conversion.

  • public static String toJson(Object object, Map<String,Object> config)

    Convert an object to a character string in JSON format and use the configuration in the config file.

    For example, you can set "date-format" in config to "yyyy-MM-dd HH:mm:ss".

    Input Parameter

    • object indicates an object.
    • config indicates the configuration used for conversion.

    Returns

    Character string in JSON format obtained after conversion.

  • public static Map<String,Object> toMap(String json)

    Convert JSON into MAP.

    Input Parameter

    json indicates a character string in JSON format.

    Returns

    Character string in MAP format.