fm.liveswitch.JsonSerializer Class Reference

Provides methods for serializing/deserializing .NET value types to/from JSON as well as facilities for converting objects and arrays if appropriate callbacks are supplied to assist with the conversion. More...

Public Member Functions

 JsonSerializer ()
 

Static Public Member Functions

static fm.liveswitch.NullableBoolean deserializeBoolean (String valueJson)
 Deserializes a boolean value. More...
 
static boolean[] deserializeBooleanArray (String arrayJson)
 Deserializes a boolean array from JSON. More...
 
static fm.liveswitch.NullableBigDecimal deserializeDecimal (String valueJson)
 Deserializes a decimal value. More...
 
static java.math.BigDecimal[] deserializeDecimalArray (String arrayJson)
 Deserializes a decimal array from JSON. More...
 
static< T > java.util.HashMap< String, T > deserializeDictionary (String dictionaryJson, fm.liveswitch.IFunction0< java.util.HashMap< String, T >> createDictionaryCallback, final fm.liveswitch.IFunction1< String, T > deserializeValueCallback)
 Deserializes a JSON string into a dictionary. More...
 
static fm.liveswitch.NullableDouble deserializeDouble (String valueJson)
 Deserializes a double value. More...
 
static double[] deserializeDoubleArray (String arrayJson)
 Deserializes a double array from JSON. More...
 
static fm.liveswitch.NullableFloat deserializeFloat (String valueJson)
 Deserializes a float value. More...
 
static float[] deserializeFloatArray (String arrayJson)
 Deserializes a float array from JSON. More...
 
static fm.liveswitch.NullableGuid deserializeGuid (String valueJson)
 Deserializes a globally unique identifier. More...
 
static fm.liveswitch.Guid[] deserializeGuidArray (String arrayJson)
 Deserializes a GUID array from JSON. More...
 
static fm.liveswitch.NullableInteger deserializeInteger (String valueJson)
 Deserializes an integer value. More...
 
static int[] deserializeIntegerArray (String arrayJson)
 Deserializes a integer array from JSON. More...
 
static fm.liveswitch.NullableLong deserializeLong (String valueJson)
 Deserializes a long value. More...
 
static long[] deserializeLongArray (String arrayJson)
 Deserializes a long array from JSON. More...
 
static< T > T deserializeObject (String json, fm.liveswitch.IFunction0< T > creator, fm.liveswitch.IAction3< T, String, String > callback)
 Deserializes a JSON string into a target object type. More...
 
static< T > java.util.ArrayList< T > deserializeObjectArray (String json, fm.liveswitch.IFunction1< String, T > deserializer)
 Deserializes a JSON string into an array of target object types. More...
 
static< T extends fm.liveswitch.Serializable > T deserializeObjectFast (String json, fm.liveswitch.IFunction0< T > creator, fm.liveswitch.IAction3< T, String, String > callback)
 Deserializes a JSON string into a fm.liveswitch.Serializable target object type. More...
 
static String deserializeRaw (String dataJson)
 Deserializes a piece of raw JSON. More...
 
static java.util.ArrayList< String > deserializeRawArray (String json)
 Deserializes a raw array from JSON. More...
 
static String deserializeString (String valueJson)
 Deserializes a string. More...
 
static String[] deserializeStringArray (String arrayJson)
 Deserializes a simple string array from JSON. More...
 
static String escapeString (String text)
 Escapes any special characters in a string. More...
 
static boolean isValidJson (String json)
 Determines whether the specified JSON string is valid. More...
 
static String serializeBoolean (fm.liveswitch.NullableBoolean value)
 Serializes a boolean value. More...
 
static String serializeBooleanArray (boolean[] array)
 Serializes a boolean array to JSON. More...
 
static String serializeDecimal (fm.liveswitch.NullableBigDecimal value)
 Serializes a decimal value. More...
 
static String serializeDecimalArray (java.math.BigDecimal[] array)
 Serializes a decimal array to JSON. More...
 
static< T > String serializeDictionary (java.util.HashMap< String, T > dictionary, final fm.liveswitch.IFunction1< T, String > serializeValueCallback)
 Serializes a dictionary into a JSON string. More...
 
static String serializeDouble (fm.liveswitch.NullableDouble value)
 Serializes a double value. More...
 
static String serializeDoubleArray (double[] array)
 Serializes a double array to JSON. More...
 
static String serializeFloat (fm.liveswitch.NullableFloat value)
 Serializes a float value. More...
 
static String serializeFloatArray (float[] array)
 Serializes a float array to JSON. More...
 
static String serializeGuid (fm.liveswitch.NullableGuid value)
 Serializes a globally unique identifier. More...
 
static String serializeGuidArray (fm.liveswitch.Guid[] array)
 Serializes a GUID array to JSON. More...
 
static String serializeInteger (fm.liveswitch.NullableInteger value)
 Serializes an integer value. More...
 
static String serializeIntegerArray (int[] array)
 Serializes a integer array to JSON. More...
 
static String serializeLong (fm.liveswitch.NullableLong value)
 Serializes a long value. More...
 
static String serializeLongArray (long[] array)
 Serializes a long array to JSON. More...
 
static< T > String serializeObject (T source, fm.liveswitch.IAction2< T, java.util.HashMap< String, String >> callback)
 Serializes an object into a JSON string. More...
 
static< T > String serializeObjectArray (T[] objects, fm.liveswitch.IFunction1< T, String > serializer)
 Serializes an object array into a JSON string. More...
 
static< T extends fm.liveswitch.Serializable > String serializeObjectFast (T source, fm.liveswitch.IAction2< T, java.util.HashMap< String, String >> callback)
 Serializes a fm.liveswitch.Serializable object into a JSON string. More...
 
static String serializeRaw (String dataJson)
 Serializes a piece of raw JSON. More...
 
static String serializeRawArray (String[] jsons)
 Serializes a raw array to JSON. More...
 
static String serializeString (String value)
 Serializes a string. More...
 
static String serializeStringArray (String[] array)
 Serializes a string array to JSON. More...
 
static String trimQuotes (String value)
 Trims the quotes from a JavaScript string value. More...
 
static String unescapeString (String text)
 Unescapes any special characters from a string. More...
 

Detailed Description

Provides methods for serializing/deserializing .NET value types to/from JSON as well as facilities for converting objects and arrays if appropriate callbacks are supplied to assist with the conversion.

Constructor & Destructor Documentation

◆ JsonSerializer()

fm.liveswitch.JsonSerializer.JsonSerializer ( )

Member Function Documentation

◆ deserializeBoolean()

static fm.liveswitch.NullableBoolean fm.liveswitch.JsonSerializer.deserializeBoolean ( String  valueJson)
static

Deserializes a boolean value.

Parameters
valueJsonThe boolean JSON to deserialize.
Returns
The deserialized boolean value.

◆ deserializeBooleanArray()

static boolean [] fm.liveswitch.JsonSerializer.deserializeBooleanArray ( String  arrayJson)
static

Deserializes a boolean array from JSON.

Parameters
arrayJsonA JSON-serialized boolean array.
Returns
An array of boolean values.

◆ deserializeDecimal()

static fm.liveswitch.NullableBigDecimal fm.liveswitch.JsonSerializer.deserializeDecimal ( String  valueJson)
static

Deserializes a decimal value.

Parameters
valueJsonThe decimal JSON to deserialize.
Returns
The deserialized decimal value.

◆ deserializeDecimalArray()

static java.math.BigDecimal [] fm.liveswitch.JsonSerializer.deserializeDecimalArray ( String  arrayJson)
static

Deserializes a decimal array from JSON.

Parameters
arrayJsonA JSON-serialized decimal array.
Returns
An array of decimal values.

◆ deserializeDictionary()

static <T> java.util.HashMap<String,T> fm.liveswitch.JsonSerializer.deserializeDictionary ( String  dictionaryJson,
fm.liveswitch.IFunction0< java.util.HashMap< String, T >>  createDictionaryCallback,
final fm.liveswitch.IFunction1< String, T >  deserializeValueCallback 
)
static

Deserializes a JSON string into a dictionary.

Parameters
dictionaryJsonThe JSON-encoded dictionary.
createDictionaryCallbackThe callback that creates a blank dictionary.
deserializeValueCallbackThe callback that deserializes a value.
Returns
The deserialized dictionary.

◆ deserializeDouble()

static fm.liveswitch.NullableDouble fm.liveswitch.JsonSerializer.deserializeDouble ( String  valueJson)
static

Deserializes a double value.

Parameters
valueJsonThe double JSON to deserialize.
Returns
The deserialized double value.

◆ deserializeDoubleArray()

static double [] fm.liveswitch.JsonSerializer.deserializeDoubleArray ( String  arrayJson)
static

Deserializes a double array from JSON.

Parameters
arrayJsonA JSON-serialized double array.
Returns
An array of double values.

◆ deserializeFloat()

static fm.liveswitch.NullableFloat fm.liveswitch.JsonSerializer.deserializeFloat ( String  valueJson)
static

Deserializes a float value.

Parameters
valueJsonThe float JSON to deserialize.
Returns
The deserialized float value.

◆ deserializeFloatArray()

static float [] fm.liveswitch.JsonSerializer.deserializeFloatArray ( String  arrayJson)
static

Deserializes a float array from JSON.

Parameters
arrayJsonA JSON-serialized float array.
Returns
An array of float values.

◆ deserializeGuid()

static fm.liveswitch.NullableGuid fm.liveswitch.JsonSerializer.deserializeGuid ( String  valueJson)
static

Deserializes a globally unique identifier.

Parameters
valueJsonThe GUID JSON to deserialize.
Returns
The deserialized GUID.

◆ deserializeGuidArray()

static fm.liveswitch.Guid [] fm.liveswitch.JsonSerializer.deserializeGuidArray ( String  arrayJson)
static

Deserializes a GUID array from JSON.

Parameters
arrayJsonA JSON-serialized GUID array.
Returns
An array of GUID values.

◆ deserializeInteger()

static fm.liveswitch.NullableInteger fm.liveswitch.JsonSerializer.deserializeInteger ( String  valueJson)
static

Deserializes an integer value.

Parameters
valueJsonThe integer JSON to deserialize.
Returns
The deserialized integer value.

◆ deserializeIntegerArray()

static int [] fm.liveswitch.JsonSerializer.deserializeIntegerArray ( String  arrayJson)
static

Deserializes a integer array from JSON.

Parameters
arrayJsonA JSON-serialized integer array.
Returns
An array of integer values.

◆ deserializeLong()

static fm.liveswitch.NullableLong fm.liveswitch.JsonSerializer.deserializeLong ( String  valueJson)
static

Deserializes a long value.

Parameters
valueJsonThe long JSON to deserialize.
Returns
The deserialized long value.

◆ deserializeLongArray()

static long [] fm.liveswitch.JsonSerializer.deserializeLongArray ( String  arrayJson)
static

Deserializes a long array from JSON.

Parameters
arrayJsonA JSON-serialized long array.
Returns
An array of long values.

◆ deserializeObject()

static <T> T fm.liveswitch.JsonSerializer.deserializeObject ( String  json,
fm.liveswitch.IFunction0< T >  creator,
fm.liveswitch.IAction3< T, String, String >  callback 
)
static

Deserializes a JSON string into a target object type.

Parameters
jsonThe JSON-encoded string.
creatorThe method used for creating a new object.
callbackThe method used for deserializing a property.
Returns
The deserialized object.

◆ deserializeObjectArray()

static <T> java.util.ArrayList<T> fm.liveswitch.JsonSerializer.deserializeObjectArray ( String  json,
fm.liveswitch.IFunction1< String, T >  deserializer 
)
static

Deserializes a JSON string into an array of target object types.

Parameters
jsonThe JSON-encoded string.
deserializerThe callback used to deserialize each item in the array.
Returns
An array of deserialized objects.

◆ deserializeObjectFast()

static <T extends fm.liveswitch.Serializable> T fm.liveswitch.JsonSerializer.deserializeObjectFast ( String  json,
fm.liveswitch.IFunction0< T >  creator,
fm.liveswitch.IAction3< T, String, String >  callback 
)
static

Deserializes a JSON string into a fm.liveswitch.Serializable target object type.

Parameters
jsonThe JSON-encoded string.
creatorThe method used for creating a new object.
callbackThe method used for deserializing a property.
Returns
The deserialized object.

◆ deserializeRaw()

static String fm.liveswitch.JsonSerializer.deserializeRaw ( String  dataJson)
static

Deserializes a piece of raw JSON.

Parameters
dataJsonThe raw data.
Returns
The deserialized data.

◆ deserializeRawArray()

static java.util.ArrayList<String> fm.liveswitch.JsonSerializer.deserializeRawArray ( String  json)
static

Deserializes a raw array from JSON.

Parameters
jsonA JSON-serialized raw array.
Returns
An array of raw values.

◆ deserializeString()

static String fm.liveswitch.JsonSerializer.deserializeString ( String  valueJson)
static

Deserializes a string.

Parameters
valueJsonThe string to deserialize.
Returns
The deserialized string value.

◆ deserializeStringArray()

static String [] fm.liveswitch.JsonSerializer.deserializeStringArray ( String  arrayJson)
static

Deserializes a simple string array from JSON.

Parameters
arrayJsonA JSON-serialized string array.
Returns
An array of string values.

◆ escapeString()

static String fm.liveswitch.JsonSerializer.escapeString ( String  text)
static

Escapes any special characters in a string.

Parameters
textThe string without escaped characters.
Returns
The escaped string.

◆ isValidJson()

static boolean fm.liveswitch.JsonSerializer.isValidJson ( String  json)
static

Determines whether the specified JSON string is valid.

Parameters
jsonThe JSON string to validate.
Returns
True if the JSON string is valid; false otherwise.

◆ serializeBoolean()

static String fm.liveswitch.JsonSerializer.serializeBoolean ( fm.liveswitch.NullableBoolean  value)
static

Serializes a boolean value.

Parameters
valueThe boolean to serialize.
Returns
The serialized boolean value.

◆ serializeBooleanArray()

static String fm.liveswitch.JsonSerializer.serializeBooleanArray ( boolean[]  array)
static

Serializes a boolean array to JSON.

Parameters
arrayAn array of boolean values.
Returns
A JSON-serialized boolean array.

◆ serializeDecimal()

static String fm.liveswitch.JsonSerializer.serializeDecimal ( fm.liveswitch.NullableBigDecimal  value)
static

Serializes a decimal value.

Parameters
valueThe decimal to serialize.
Returns
The serialized decimal value.

◆ serializeDecimalArray()

static String fm.liveswitch.JsonSerializer.serializeDecimalArray ( java.math.BigDecimal[]  array)
static

Serializes a decimal array to JSON.

Parameters
arrayAn array of decimal values.
Returns
A JSON-serialized decimal array.

◆ serializeDictionary()

static <T> String fm.liveswitch.JsonSerializer.serializeDictionary ( java.util.HashMap< String, T >  dictionary,
final fm.liveswitch.IFunction1< T, String >  serializeValueCallback 
)
static

Serializes a dictionary into a JSON string.

Parameters
dictionaryThe dictionary being serialized.
serializeValueCallbackThe callback that serializes a value.
Returns
The dictionary as a JSON string.

◆ serializeDouble()

static String fm.liveswitch.JsonSerializer.serializeDouble ( fm.liveswitch.NullableDouble  value)
static

Serializes a double value.

Parameters
valueThe double to serialize.
Returns
The serialized double value.

◆ serializeDoubleArray()

static String fm.liveswitch.JsonSerializer.serializeDoubleArray ( double[]  array)
static

Serializes a double array to JSON.

Parameters
arrayAn array of double values.
Returns
A JSON-serialized double array.

◆ serializeFloat()

static String fm.liveswitch.JsonSerializer.serializeFloat ( fm.liveswitch.NullableFloat  value)
static

Serializes a float value.

Parameters
valueThe float to serialize.
Returns
The serialized float value.

◆ serializeFloatArray()

static String fm.liveswitch.JsonSerializer.serializeFloatArray ( float[]  array)
static

Serializes a float array to JSON.

Parameters
arrayAn array of float values.
Returns
A JSON-serialized float array.

◆ serializeGuid()

static String fm.liveswitch.JsonSerializer.serializeGuid ( fm.liveswitch.NullableGuid  value)
static

Serializes a globally unique identifier.

Parameters
valueThe GUID to serialize.
Returns
The serialized GUID.

◆ serializeGuidArray()

static String fm.liveswitch.JsonSerializer.serializeGuidArray ( fm.liveswitch.Guid[]  array)
static

Serializes a GUID array to JSON.

Parameters
arrayAn array of GUID values.
Returns
A JSON-serialized GUID array.

◆ serializeInteger()

static String fm.liveswitch.JsonSerializer.serializeInteger ( fm.liveswitch.NullableInteger  value)
static

Serializes an integer value.

Parameters
valueThe integer to serialize.
Returns
The serialized integer value.

◆ serializeIntegerArray()

static String fm.liveswitch.JsonSerializer.serializeIntegerArray ( int[]  array)
static

Serializes a integer array to JSON.

Parameters
arrayAn array of integer values.
Returns
A JSON-serialized integer array.

◆ serializeLong()

static String fm.liveswitch.JsonSerializer.serializeLong ( fm.liveswitch.NullableLong  value)
static

Serializes a long value.

Parameters
valueThe long to serialize.
Returns
The serialized long value.

◆ serializeLongArray()

static String fm.liveswitch.JsonSerializer.serializeLongArray ( long[]  array)
static

Serializes a long array to JSON.

Parameters
arrayAn array of long values.
Returns
A JSON-serialized long array.

◆ serializeObject()

static <T> String fm.liveswitch.JsonSerializer.serializeObject ( source,
fm.liveswitch.IAction2< T, java.util.HashMap< String, String >>  callback 
)
static

Serializes an object into a JSON string.

Parameters
sourceThe object being serialized.
callbackThe method used for serializing properties.
Returns
The object as a JSON string.

◆ serializeObjectArray()

static <T> String fm.liveswitch.JsonSerializer.serializeObjectArray ( T[]  objects,
fm.liveswitch.IFunction1< T, String >  serializer 
)
static

Serializes an object array into a JSON string.

Parameters
objectsThe object array being serialized.
serializerThe callback used to serialize each item in the array.
Returns
The object array as a JSON string.

◆ serializeObjectFast()

static <T extends fm.liveswitch.Serializable> String fm.liveswitch.JsonSerializer.serializeObjectFast ( source,
fm.liveswitch.IAction2< T, java.util.HashMap< String, String >>  callback 
)
static

Serializes a fm.liveswitch.Serializable object into a JSON string.

Parameters
sourceThe object being serialized.
callbackThe method used for serializing properties.
Returns
The object as a JSON string.

◆ serializeRaw()

static String fm.liveswitch.JsonSerializer.serializeRaw ( String  dataJson)
static

Serializes a piece of raw JSON.

Parameters
dataJsonThe raw data.
Returns
The serialized data.

◆ serializeRawArray()

static String fm.liveswitch.JsonSerializer.serializeRawArray ( String[]  jsons)
static

Serializes a raw array to JSON.

Parameters
jsonsAn array of raw values.
Returns
A JSON-serialized raw array.

◆ serializeString()

static String fm.liveswitch.JsonSerializer.serializeString ( String  value)
static

Serializes a string.

Parameters
valueThe string to serialize.
Returns
The serialized string value.

◆ serializeStringArray()

static String fm.liveswitch.JsonSerializer.serializeStringArray ( String[]  array)
static

Serializes a string array to JSON.

Parameters
arrayAn array of string values.
Returns
A JSON-serialized string array.

◆ trimQuotes()

static String fm.liveswitch.JsonSerializer.trimQuotes ( String  value)
static

Trims the quotes from a JavaScript string value.

Parameters
valueThe JavaScript string value.
Returns
The string without quotes.

◆ unescapeString()

static String fm.liveswitch.JsonSerializer.unescapeString ( String  text)
static

Unescapes any special characters from a string.

Parameters
textThe string with escaped characters.
Returns
The unescaped string.