Package org.rapidcontext.core.data
Class JsonSerializer
java.lang.Object
org.rapidcontext.core.data.JsonSerializer
A data serializer and unserializer for the JSON format. The object
mapping to JSON is not exact, and may omit serialization of data
in some cases. The following basic requirements must be met in
order to serialize an object:
- No circular references are permitted.
- String, Number, Boolean, Date, Array and Dict values are supported.
- Version:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Serializes an object into a JSON representation.static void
serialize
(Object obj, OutputStream os) Serializes an object into a JSON representation.static Object
Unserializes JSON data into a Java object.static Object
unserialize
(String json) Unserializes JSON data into a Java object.
-
Method Details
-
serialize
Serializes an object into a JSON representation.- Parameters:
obj
- the object to convert, or nullos
- the output stream to write to- Throws:
IOException
- if the data couldn't be serialized
-
serialize
Serializes an object into a JSON representation. If the indentation flag is set, the JSON data will be indented and formatted. Otherwise a minimal string will be returned.- Parameters:
obj
- the object to convert, or nullindent
- the indentation flag- Returns:
- a JSON data representation
-
unserialize
Unserializes JSON data into a Java object. Returns the corresponding String, Number, Boolean, Dict or Array value.- Parameters:
is
- the input stream to load- Returns:
- the Java data representation
- Throws:
IOException
- if the unserialization failed
-
unserialize
Unserializes JSON data into a Java object. Returns the corresponding String, Number, Boolean, Dict or Array value.- Parameters:
json
- the JSON data to convert- Returns:
- the Java data representation
- Throws:
IOException
- if the unserialization failed
-