Class JSONUtil
- java.lang.Object
-
- com.github.toolarium.enumeration.configuration.util.JSONUtil
-
public final class JSONUtil extends java.lang.Object
Simple JSON util
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.String>
convert(java.lang.String json)
Convert a JSON array into a list of stringsjava.lang.String
convert(java.util.List<java.lang.String> list)
Convert a list of strings into a JSON arraystatic JSONUtil
getInstance()
Get the instance<T> T
read(java.lang.Class<T> type, java.io.InputStream inputstream)
Reads an object from an input stream.<T> void
write(T type, java.io.OutputStream outputStream)
Writes an object to an output stream.
-
-
-
Method Detail
-
getInstance
public static JSONUtil getInstance()
Get the instance- Returns:
- the instance
-
read
public <T> T read(java.lang.Class<T> type, java.io.InputStream inputstream) throws java.io.IOException
Reads an object from an input stream.- Type Parameters:
T
- the generic type- Parameters:
type
- the classinputstream
- the input stream- Returns:
- the read object
- Throws:
java.io.IOException
- In case of an error
-
write
public <T> void write(T type, java.io.OutputStream outputStream) throws java.io.IOException
Writes an object to an output stream.- Type Parameters:
T
- the generic type- Parameters:
type
- the object to writeoutputStream
- the output stream- Throws:
java.io.IOException
- In case of an error
-
convert
public java.lang.String convert(java.util.List<java.lang.String> list) throws java.lang.IllegalArgumentException
Convert a list of strings into a JSON array- Parameters:
list
- the string list- Returns:
- the list as json array
- Throws:
java.lang.IllegalArgumentException
- In case of invalid json format
-
convert
public java.util.List<java.lang.String> convert(java.lang.String json) throws java.lang.IllegalArgumentException
Convert a JSON array into a list of strings- Parameters:
json
- the json array- Returns:
- the json array as string list
- Throws:
java.lang.IllegalArgumentException
- In case of invalid json format
-
-