SMILA (incubation) API documentation

org.eclipse.smila.datamodel.json
Class JsonSerializationUtils

java.lang.Object
  extended by org.eclipse.smila.datamodel.json.JsonSerializationUtils

public class JsonSerializationUtils
extends java.lang.Object

Utility class for converting datamodel objects to JSON objects and vice versa.

Author:
aweber

Field Summary
protected  DataFactory _dataFactory
          Data factory to use.
protected  ValueFormatHelper _formatHelper
          helper for parsing date/datetimes.
protected  IpcFactory _jsonFactory
          JSON IPC factory.
static java.lang.String ENCODING
          Encoding to use for String (de)serialization.
 
Constructor Summary
JsonSerializationUtils()
           
 
Method Summary
 void any2JsonStream(java.io.OutputStream stream, Any object)
          Converts Any object to JSON stream.
 void any2Stream(IpcStreamWriter writer, Any object)
          Converts Any object to IPC stream.
 Record jsonObject2record(java.lang.String jsonString)
          Converts JSON string to record object.
 Any jsonStream2any(java.io.InputStream stream)
          Converts JSON stream to Any object.
 Record jsonStream2record(java.io.InputStream stream)
          Converts JSON stream to record object.
 java.lang.String map2JsonObject(AnyMap object)
          Converts AnyMap object to JSON object.
 void map2JsonStream(java.io.OutputStream stream, AnyMap object)
          Converts AnyMap object to JSON stream.
 java.lang.String record2JsonObject(Record record)
          Converts record object to JSON object.
 void record2JsonStream(java.io.OutputStream stream, Record record)
          Converts record object to JSON stream.
 void record2Stream(IpcStreamWriter writer, Record record)
          Converts record object to stream.
 Any stream2any(IpcStreamReader reader)
          Converts stream to record object.
 Record stream2record(IpcStreamReader reader)
          Converts stream to record object.
 Record stream2record(IpcStreamReader reader, boolean required)
          Converts stream to record object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING

public static final java.lang.String ENCODING
Encoding to use for String (de)serialization.

See Also:
Constant Field Values

_dataFactory

protected final DataFactory _dataFactory
Data factory to use.


_jsonFactory

protected final IpcFactory _jsonFactory
JSON IPC factory.


_formatHelper

protected final ValueFormatHelper _formatHelper
helper for parsing date/datetimes.

Constructor Detail

JsonSerializationUtils

public JsonSerializationUtils()
Method Detail

jsonObject2record

public Record jsonObject2record(java.lang.String jsonString)
                         throws java.io.IOException
Converts JSON string to record object.

Parameters:
jsonString - input object
Returns:
record object
Throws:
java.io.IOException - in case of conversion error

jsonStream2record

public Record jsonStream2record(java.io.InputStream stream)
                         throws java.io.IOException
Converts JSON stream to record object.

Parameters:
stream - an input stream
Returns:
a record with no Id set
Throws:
java.io.IOException - in case of conversion error

jsonStream2any

public Any jsonStream2any(java.io.InputStream stream)
                   throws java.io.IOException
Converts JSON stream to Any object.

Parameters:
stream - an input stream
Returns:
a record with no Id set
Throws:
java.io.IOException - in case of conversion error

stream2record

public Record stream2record(IpcStreamReader reader)
                     throws java.io.IOException
Converts stream to record object.

Parameters:
reader - an ipc reader (binary/json)
Returns:
a record with no Id set
Throws:
java.io.IOException - IO errors from underlying stream.
java.lang.IllegalStateException - parse errors.

stream2record

public Record stream2record(IpcStreamReader reader,
                            boolean required)
                     throws java.io.IOException
Converts stream to record object.

Parameters:
reader - an ipc reader (binary/json)
required - if true an exception if there is no next record on the stream. if false, just return null.
Returns:
a record with no Id set
Throws:
java.io.IOException - IO errors from underlying stream.
java.lang.IllegalStateException - parse errors.

stream2any

public Any stream2any(IpcStreamReader reader)
               throws java.io.IOException
Converts stream to record object.

Parameters:
reader - an ipc reader (binary/json)
Returns:
an Any
Throws:
java.io.IOException - in case of conversion error

record2JsonObject

public java.lang.String record2JsonObject(Record record)
                                   throws java.io.IOException
Converts record object to JSON object.

Parameters:
record - input record
Returns:
JSON string representing the record.
Throws:
java.io.IOException - in case of conversion error

record2JsonStream

public void record2JsonStream(java.io.OutputStream stream,
                              Record record)
                       throws java.io.IOException
Converts record object to JSON stream.

Parameters:
stream - output stream
record - input record
Throws:
java.io.IOException - in case of conversion error

map2JsonStream

public void map2JsonStream(java.io.OutputStream stream,
                           AnyMap object)
                    throws java.io.IOException
Converts AnyMap object to JSON stream.

Parameters:
stream - output stream
object - input record
Throws:
java.io.IOException - in case of conversion error

map2JsonObject

public java.lang.String map2JsonObject(AnyMap object)
                                throws java.io.IOException
Converts AnyMap object to JSON object.

Parameters:
object - an AnyMap object
Returns:
JSON string representing the input object.
Throws:
java.io.IOException - in case of conversion error

any2JsonStream

public void any2JsonStream(java.io.OutputStream stream,
                           Any object)
                    throws java.io.IOException
Converts Any object to JSON stream.

Parameters:
stream - output stream
object - input object
Throws:
java.io.IOException - in case of conversion error

any2Stream

public void any2Stream(IpcStreamWriter writer,
                       Any object)
                throws java.io.IOException
Converts Any object to IPC stream.

Parameters:
writer - an IPC writer
object - input object
Throws:
java.io.IOException - in case of conversion error

record2Stream

public void record2Stream(IpcStreamWriter writer,
                          Record record)
                   throws java.io.IOException
Converts record object to stream.

Parameters:
writer - an ipc stream writer (bon/json)
record - input record
Throws:
java.io.IOException - in case of conversion error

SMILA (incubation) API documentation