Package org.xipki.util
Class JSON
- java.lang.Object
-
- org.xipki.util.JSON
-
public class JSON extends java.lang.ObjectJSON util class- Since:
- 6.1.0
- Author:
- Lijun Liao (xipki)
-
-
Constructor Summary
Constructors Constructor Description JSON()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConfPairsdeserializerConfPairs(com.fasterxml.jackson.core.JsonParser jsonParser)static com.fasterxml.jackson.databind.ObjectMappernewDefaultObjectMapper()static <T> TparseConf(byte[] json, java.lang.Class<T> classOfT)static <T> TparseConf(java.io.File jsonFile, java.lang.Class<T> classOfT)static <T> TparseConf(java.io.InputStream jsonInputStream, java.lang.Class<T> classOfT)static <T> TparseConf(java.lang.String json, java.lang.Class<T> classOfT)static <T> TparseConf(java.nio.file.Path jsonFilePath, java.lang.Class<T> classOfT)static <T> TparseObject(byte[] json, java.lang.Class<T> classOfT)static <T> TparseObject(java.io.File jsonFile, java.lang.Class<T> classOfT)static <T> TparseObject(java.io.InputStream jsonInputStream, java.lang.Class<T> classOfT)Deserialize the object from the input stream.static <T> TparseObject(java.lang.String json, java.lang.Class<T> classOfT)static <T> TparseObject(java.nio.file.Path jsonFilePath, java.lang.Class<T> classOfT)static <T> TparseObjectAndClose(java.io.InputStream jsonInputStream, java.lang.Class<T> classOfT)Deserialize the object from the input stream and closes the inputstream.static java.lang.StringtoJson(java.lang.Object obj)static byte[]toJSONBytes(java.lang.Object obj)static java.lang.StringtoPrettyJson(java.lang.Object obj)static voidwriteJSON(java.lang.Object object, java.io.OutputStream outputStream)Serialize the object to the output stream.static voidwriteJSONAndClose(java.lang.Object object, java.io.OutputStream outputStream)Serialize the object to the output stream.static voidwritePrettyJSON(java.lang.Object object, java.io.OutputStream outputStream)Serialize the object in pretty format to the output stream.static voidwritePrettyJSONAndClose(java.lang.Object object, java.io.OutputStream outputStream)Serialize the object in pretty format to the output stream.
-
-
-
Method Detail
-
newDefaultObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper newDefaultObjectMapper()
-
parseObject
public static <T> T parseObject(java.lang.String json, java.lang.Class<T> classOfT)
-
parseObject
public static <T> T parseObject(byte[] json, java.lang.Class<T> classOfT)
-
parseObject
public static <T> T parseObject(java.nio.file.Path jsonFilePath, java.lang.Class<T> classOfT) throws java.io.IOException- Throws:
java.io.IOException
-
parseObject
public static <T> T parseObject(java.io.File jsonFile, java.lang.Class<T> classOfT) throws java.io.IOException- Throws:
java.io.IOException
-
parseConf
public static <T> T parseConf(byte[] json, java.lang.Class<T> classOfT)
-
parseConf
public static <T> T parseConf(java.lang.String json, java.lang.Class<T> classOfT)
-
parseConf
public static <T> T parseConf(java.io.File jsonFile, java.lang.Class<T> classOfT) throws java.io.IOException- Throws:
java.io.IOException
-
parseConf
public static <T> T parseConf(java.nio.file.Path jsonFilePath, java.lang.Class<T> classOfT) throws java.io.IOException- Throws:
java.io.IOException
-
parseConf
public static <T> T parseConf(java.io.InputStream jsonInputStream, java.lang.Class<T> classOfT) throws java.io.IOException- Throws:
java.io.IOException
-
parseObject
public static <T> T parseObject(java.io.InputStream jsonInputStream, java.lang.Class<T> classOfT) throws java.io.IOExceptionDeserialize the object from the input stream. The specified stream remains open after this method returns.- Type Parameters:
T- the object type of serialized object.- Parameters:
jsonInputStream- the input stream containing the serialized object.classOfT- the class of deserialized object.- Returns:
- the serialized object
- Throws:
java.io.IOException- if IO error occurs while reading the stream.
-
parseObjectAndClose
public static <T> T parseObjectAndClose(java.io.InputStream jsonInputStream, java.lang.Class<T> classOfT) throws java.io.IOExceptionDeserialize the object from the input stream and closes the inputstream. The specified stream is closed after this method returns.- Type Parameters:
T- the object type of serialized object.- Parameters:
jsonInputStream- the input stream containing the serialized object.classOfT- the class of deserialized object.- Returns:
- the serialized object
- Throws:
java.io.IOException- if IO error occurs while reading the stream.
-
toJson
public static java.lang.String toJson(java.lang.Object obj)
-
toJSONBytes
public static byte[] toJSONBytes(java.lang.Object obj)
-
toPrettyJson
public static java.lang.String toPrettyJson(java.lang.Object obj)
-
writeJSON
public static void writeJSON(java.lang.Object object, java.io.OutputStream outputStream) throws java.io.IOExceptionSerialize the object to the output stream. The specified stream remains open after this method returns.- Parameters:
object- object to be serialized.outputStream- output stream to which the serialized object is written.- Throws:
java.io.IOException- if IO error occurs while writting to the stream.
-
writeJSONAndClose
public static void writeJSONAndClose(java.lang.Object object, java.io.OutputStream outputStream) throws java.io.IOExceptionSerialize the object to the output stream. The specified stream is closed after this method returns.- Parameters:
object- object to be serialized.outputStream- output stream to which the serialized object is written.- Throws:
java.io.IOException- if IO error occurs while writting to the stream.
-
writePrettyJSON
public static void writePrettyJSON(java.lang.Object object, java.io.OutputStream outputStream) throws java.io.IOExceptionSerialize the object in pretty format to the output stream. The specified stream remains open after this method returns.- Parameters:
object- object to be serialized.outputStream- output stream to which the serialized object is written.- Throws:
java.io.IOException- if IO error occurs while writting to the stream.
-
writePrettyJSONAndClose
public static void writePrettyJSONAndClose(java.lang.Object object, java.io.OutputStream outputStream) throws java.io.IOExceptionSerialize the object in pretty format to the output stream. The specified stream is closed after this method returns.- Parameters:
object- object to be serialized.outputStream- output stream to which the serialized object is written.- Throws:
java.io.IOException- if IO error occurs while writting to the stream.
-
deserializerConfPairs
public static ConfPairs deserializerConfPairs(com.fasterxml.jackson.core.JsonParser jsonParser) throws java.io.IOException
- Throws:
java.io.IOException
-
-