public class JsonHelper extends Object
Modifier and Type | Method and Description |
---|---|
static String |
cleanControlChars(String value)
Clean control characters in a string.
|
static String |
escapeControlChars(String value)
Escapes control characters in a string.
|
static String |
sanitize(String value)
Escapes control characters in a string.
|
static String |
sanitize(String value,
boolean clean) |
static String |
sanitize(String value,
boolean clean,
Character... toEscape)
Escapes control characters in a string when you need to
generate JSON.
|
static String |
toJsonObject(Object... namesAndValues)
Converts input into a JSON object.
|
static String |
toJsonString(Object val)
Convert Java object to a JSON string.
|
static String |
toJsonString(Object val,
boolean pretty)
Convert Java object to a JSON string.
|
static List |
toList(String json)
Convert JSON array tp Java List
|
static Map |
toMap(String json)
Convert a JSON map to a Java Map
|
static Map[] |
toMaps(String json)
Convert JSON Array to Java array of maps.
|
public static Map toMap(String json)
json
- JSON mappublic static Map[] toMaps(String json)
json
- JSON arraypublic static String toJsonString(Object val)
val
- Java objectpublic static String toJsonString(Object val, boolean pretty)
val
- Java objectpretty
- enable/disable pretty printpublic static String toJsonObject(Object... namesAndValues)
namesAndValues
- - expected sequence of corresponding name and value pairs (number of parameters must be even ).public static List toList(String json)
json
- JSON array string.public static String cleanControlChars(String value)
value
- string to escapepublic static String escapeControlChars(String value)
value
- string to escapesanitize(String)
public static String sanitize(String value)
value
- string to escapeescapeControlChars(String)
public static String sanitize(String value, boolean clean, Character... toEscape)
value
- input stringclean
- if true will remove characters that match, if false will escapetoEscape
- array of characters to escape. If not provided, it will escape or clean '"','\\', '\t', '\b', '\n', '\r' '\f'
.
This method will only escape or clean if provided chars are from this list.clean
flag.Copyright © 2020 JavaLite. All rights reserved.