Namespace: OpenEdge.Core.Json
Type: Class JsonConverter
Parent Classes:
Progress.Lang.Object

Inherits: Progress.Lang.Object


/* *************************************************************************************************************************
Copyright (c) 2019-2021 by Progress Software Corporation and/or one of its subsidiaries or affiliates. All rights reserved.
File:JsonConverter
Description:Helps to convert to and from JSON, for common/standard (Ccs.Common.Support.I*Holder,
OpenEdge.Core.Collections.I*) types
Author(s):pjudge
Created:2019-11-21
/* Default constructor.
This is private so that this class cannot be instantiated - it's intended to be used with static members only



Method Summary
  Options Name Purpose
  AddToArray (integer, Object, JsonArray) /* Adds an instance value into a JSON array @param integer The index at which to add the value. the array may be extended to this value @param Progress.Lang.Object A value to be written for the property. May be null. @param JsonObject A JSON array. Must exist. */
  AddToObject (Object, Object, JsonObject) /* Adds a value into a JSON object for a specific key @param Progress.Lang.Object The key value - property name (required) @param Progress.Lang.Object A value to be written for the property. May be null. @param JsonObject A JSON object */
  Merge (JsonObject, JsonObject, logical) /* Merges (combines) two JSON objects. Properties are copied from the SOURCE into the TARGET. Properties are copied from the SOURCE into the TARGET. Property types must match, otherwise an error is thrown. If the property exists in the target, it is overwritten by the source property if the pOverwriteExisting flag is TRUE. @param JsonObject The target JSON object. Must exist. @param JsonObject The source JSON object. Can be null @param logical TRUE if properties from the SOURCE object should overwrite those in the TARGET */
  Progress.Json.ObjectModel.JsonArray ToArray (ICollection) /* Converts an instance of a collection into a JSONArray Invalid inputs, indeterminate arrays, all get a null value @param ICollection The input collection @return JsonArray An array instance */
  Progress.Json.ObjectModel.JsonArray ToArray (IObjectArrayHolder) /* Converts an array of objects into into a JSONArray Invalid inputs, indeterminate arrays, all get a null value @param IObjectArrayHolder The input array @return JsonArray An array instance */
  Progress.Json.ObjectModel.JsonArray ToArray (IPrimitiveArrayHolder) /* Converts an instance of a IPrimitiveArrayHolder into a JSONArray Invalid inputs, indeterminate arrays, all get a null value @param IPrimitiveArrayHolder The input value @return JsonArray An array instance */
  Progress.Json.ObjectModel.JsonArray ToArray (Object[]) /* Converts an array of objects into into a JSONArray Invalid inputs, indeterminate arrays, all get a null value @param P.L.Object[] The input array @return JsonArray An array instance */
  Progress.Lang.Enum ToEnum (JsonArray, integer, Class) /* This method converts a JSON array element to an instance of an P.L.Enum. The element value must be either a string or number. If the inputs are invalid, or the index is not in range, or the value is of the wrong JSON type, an unknown value is returned. If the ToObject() call fails, an error is raised. @param JsonArray The array @param integer The element index @param P.L.Class The type of the enum @return Progress.Lang.Enum The enum */
  Progress.Lang.Enum ToEnum (JsonObject, character, Class) /* This method converts a JSON property to an instance of an P.L.Enum. The property value must be either a string or number. If the inputs are invalid, or the property does not exist, or is of the wrong JSON type, enum, an unknown value is returned. If the ToObject() call fails, an error is raised @param JsonObject The object @param character The property name @param P.L.Class The type of the enum @return Progress.Lang.Enum The enum */
  Progress.Json.ObjectModel.JsonObject ToObject (IMap) /* Converts an instance of a KeyValuePair into a JSON Object Invalid inputs, indeterminate arrays, all get an @param IMap A map (collection of name/value pairs) @return JsonObject A JSON object */
  Progress.Json.ObjectModel.JsonObject ToObject (KeyValuePair) /* Converts an instance of a KeyValuePair into a JSON Object Invalid inputs, indeterminate arrays, all get an @param KeyValuePair A name/value pair @return JsonObject A JSON object */
  Progress.Json.ObjectModel.JsonObject ToObject (Error) /* Converts an instance of a Progress.Lang.Error into a JSON Object { _retVal: the return value, if an AppError _soapFault: If a SoapFaultError, non-empty values are written { _msg: soapFault:soap-fault-string _code: soapFault:soap-fault-code _subCode: soapFault:soap-fault-subcode _actor: soapFault:soap-fault-actor _role: soapFault:soap-fault-role _misunderstoodHeader: soap-fault-misunderstood-header _node: soapFault:soap-fault-node } _errors: [ { _errorMsg: the error message _errorNum: the error number } ] _sev: the severity of the error _type: the OOABL type of the error, if session:debug-alert _stack: the error call stack, if session:debug-alert _innerError: one of the below. if both exist in the error, then stop is used {<error-json>} if the object has a readable InnerError property of type P.L.Error, and a valid value, then call ToObject(error) {<stop-json>} if the object has a readable InnerStop property of type P.L.Stop, and a valid value, then call ToObject(stop) } @param Progress.Lang.Error An error. Must exist @return JsonObject A JSON object representing the Error */
  Progress.Json.ObjectModel.JsonObject ToObject (Object, Object) /* Converts an kay and value into a JSON Object @param Progress.Lang.Object The key value - property name (required) @param Progress.Lang.Object A value to be written for the property. May be null. @return JsonObject A JSON object */
  Progress.Json.ObjectModel.JsonObject ToObject (Stop) /* Converts an instance of a Progress.Lang.Stop into a JSON Object { _errors: [ { _errorMsg: the stop type name _errorNum: null _device: ) _tableName: ) If the stop is a LockConflict _user: ) } ] _type: if session:debug-alert _stack: if session:debug-alert } @param Progress.Lang.Stop An stop condition. Must exist @return JsonObject A JSON object representing the Error */
  OpenEdge.Core.IObjectArrayHolder ToObjectArray (JsonArray) /* Converts a JSON array to an instance of a IObjectArrayHolder @param JsonArray A JSON array. May be invalid/null @return IObjectArrayHolder The array holder. One is always returned. */
  OpenEdge.Core.IObjectArrayHolder ToObjectArray (JsonArray, Class) /* Converts a JSON array to an instance of a IObjectArrayHolder @param JsonArray A JSON array. May be invalid/null @param P.L.Class The type of the elements in the array @return IObjectArrayHolder The array holder. One is always returned. */
  Ccs.Common.Support.IPrimitiveArrayHolder ToPrimitiveArray (JsonArray) /* Converts a JSON array to an instance of a PrimitiveArrayHolder The first non-null element is used to infer the array's ABL type. Objects and Arrays are returned as JSON text. @param JsonArray A JSON array. May be invalid/null @return IPrimitiveArrayHolder The array holder. One is always returned. */
  Ccs.Common.Support.IPrimitiveHolder ToScalar (JsonArray, integer) /* This method converts a JSON array element to an instance of an IPrimitiveHolder. If the inputs are invalid, or the index is not in range, a OE.Core.String object represeting the unknown value is returned. Input JSON data types: NULL -> OE.Core.String(?) OBJECT, ARRAY -> OE.Core.String(GetJsonText) BOOLEAN -> OE.Core.LogicalValue(<val>) NUMBER -> if the value has a '.', OE.Core.Decimal(<val>), else OE.Core.Integer(<val>) STRING -> If the value looks like YYYY-MM-DD, try to parse and return OE.Core.DateHolder If the value looks like YYYY-MM-DDTHH:MM:SS.SSS, try to parse and return OE.Core.DateTimeHolder If the value looks like YYYY-MM-DDTHH:MM:SS.SSS+HH:MM, try to parse and return OE.Core.DateTimeTzHolder If the value looks like a base64-encoded value (last 2 chars are ==), return as OE.Core.Memptr If the 'looks like' or parsing fail, return OE.Core.String(<val>) If the property value cannot be converted, an object represeting the unknown value is returned (same as NULL). @param JsonArray The object @param integer The element index @return IPrimitiveHolder The representative value */
  Ccs.Common.Support.IPrimitiveHolder ToScalar (JsonObject, character) /* This method converts a JSON property to an instance of an IPrimitiveHolder. Input JSON data types: NULL -> OE.Core.String(?) OBJECT, ARRAY -> OE.Core.String(GetJsonText) BOOLEAN -> OE.Core.LogicalValue(<val>) NUMBER -> if the value has a '.', OE.Core.Decimal(<val>), else OE.Core.Integer(<val>) STRING -> If the value looks like YYYY-MM-DD, try to parse and return OE.Core.DateHolder If the value looks like YYYY-MM-DDTHH:MM:SS.SSS, try to parse and return OE.Core.DateTimeHolder If the value looks like YYYY-MM-DDTHH:MM:SS.SSS+HH:MM, try to parse and return OE.Core.DateTimeTzHolder If the value looks like a base64-encoded value (last 2 chars are ==), return as OE.Core.Memptr If the 'looks like' or parsing fail, return OE.Core.String(<val>) If the property value cannot be converted, an object represeting the unknown value is returned (same as NULL). @param JsonObject The object @param character The property name @return IPrimitiveHolder The representative value */

Constructor Summary
  Options Name Purpose
  JsonConverter () /* Default constructor. This is private so that this class cannot be instantiated - it's intended to be used with static members only */

Method Detail
Top

AddToArray (integer, Object, JsonArray)

/* Adds an instance value into a JSON array
Parameters:
pIdx INTEGER
 
pValue Progress.Lang.Object
 
pJson Progress.Json.ObjectModel.JsonArray
 
Top

AddToObject (Object, Object, JsonObject)

/* Adds a value into a JSON object for a specific key
Parameters:
pKey Progress.Lang.Object
 
pValue Progress.Lang.Object
 
pJson Progress.Json.ObjectModel.JsonObject
 
Top

Merge (JsonObject, JsonObject, logical)

/* Merges (combines) two JSON objects.
Properties are copied from the SOURCE into the TARGET.
Properties are copied from the SOURCE into the TARGET. Property types
must match, otherwise an error is thrown.
If the property exists in the target, it is overwritten by
the source property if the pOverwriteExisting flag is TRUE.
Parameters:
pTarget Progress.Json.ObjectModel.JsonObject
 
pSource Progress.Json.ObjectModel.JsonObject
 
pOverwriteExisting LOGICAL
 
Top

Progress.Json.ObjectModel.JsonArray ToArray (ICollection)

/* Converts an instance of a collection into a JSONArray
Invalid inputs, indeterminate arrays, all get a null value
Parameters:
pCollection OpenEdge.Core.Collections.ICollection
 
Returns Progress.Json.ObjectModel.JsonArray
  JsonArray An array instance
Top

Progress.Json.ObjectModel.JsonArray ToArray (IObjectArrayHolder)

/* Converts an array of objects into into a JSONArray
Invalid inputs, indeterminate arrays, all get a null value
Parameters:
pArray OpenEdge.Core.IObjectArrayHolder
 
Returns Progress.Json.ObjectModel.JsonArray
  JsonArray An array instance
Top

Progress.Json.ObjectModel.JsonArray ToArray (IPrimitiveArrayHolder)

/* Converts an instance of a IPrimitiveArrayHolder into a JSONArray
Invalid inputs, indeterminate arrays, all get a null value
Parameters:
pArray Ccs.Common.Support.IPrimitiveArrayHolder
 
Returns Progress.Json.ObjectModel.JsonArray
  JsonArray An array instance
Top

Progress.Json.ObjectModel.JsonArray ToArray (Object[])

/* Converts an array of objects into into a JSONArray
Invalid inputs, indeterminate arrays, all get a null value
Parameters:
pArray Progress.Lang.Object
 
Returns Progress.Json.ObjectModel.JsonArray
  JsonArray An array instance
Top

Progress.Lang.Enum ToEnum (JsonArray, integer, Class)

/* This method converts a JSON array element to an instance of an P.L.Enum.
The element value must be either a string or number.
If the inputs are invalid, or the index is not in range, or the value is of the wrong JSON type,
an unknown value is returned.
If the ToObject() call fails, an error is raised.
Parameters:
pArray Progress.Json.ObjectModel.JsonArray
 
pIdx INTEGER
 
pEnumType Progress.Lang.Class
 
Returns Progress.Lang.Enum
  Progress.Lang.Enum The enum
Top

Progress.Lang.Enum ToEnum (JsonObject, character, Class)

/* This method converts a JSON property to an instance of an P.L.Enum.
The property value must be either a string or number.
If the inputs are invalid, or the property does not exist, or is of the wrong JSON type,
enum, an unknown value is returned.
If the ToObject() call fails, an error is raised
Parameters:
pObject Progress.Json.ObjectModel.JsonObject
 
pName CHARACTER
 
pEnumType Progress.Lang.Class
 
Returns Progress.Lang.Enum
  Progress.Lang.Enum The enum
Top

Progress.Json.ObjectModel.JsonObject ToObject (IMap)

/* Converts an instance of a KeyValuePair into a JSON Object
Invalid inputs, indeterminate arrays, all get an
Parameters:
pMap OpenEdge.Core.Collections.IMap
 
Returns Progress.Json.ObjectModel.JsonObject
  JsonObject A JSON object
Top

Progress.Json.ObjectModel.JsonObject ToObject (KeyValuePair)

/* Converts an instance of a KeyValuePair into a JSON Object
Invalid inputs, indeterminate arrays, all get an
Parameters:
pTuple OpenEdge.Core.KeyValuePair
 
Returns Progress.Json.ObjectModel.JsonObject
  JsonObject A JSON object
Top

Progress.Json.ObjectModel.JsonObject ToObject (Error)

/* Converts an instance of a Progress.Lang.Error into a JSON Object
{
_retVal: the return value, if an AppError
_soapFault: If a SoapFaultError, non-empty values are written
{
_msg: soapFault:soap-fault-string
_code: soapFault:soap-fault-code
_subCode: soapFault:soap-fault-subcode
_actor: soapFault:soap-fault-actor
_role: soapFault:soap-fault-role
_misunderstoodHeader: soap-fault-misunderstood-header
_node: soapFault:soap-fault-node
}
_errors: [
{ _errorMsg: the error message
_errorNum: the error number
}
]
_sev: the severity of the error
_type: the OOABL type of the error, if session:debug-alert
_stack: the error call stack, if session:debug-alert
_innerError: one of the below. if both exist in the error, then stop is used
{<error-json>} if the object has a readable InnerError property of type P.L.Error, and a valid value, then call ToObject(error)
{<stop-json>} if the object has a readable InnerStop property of type P.L.Stop, and a valid value, then call ToObject(stop)
}
Parameters:
pError Progress.Lang.Error
 
Returns Progress.Json.ObjectModel.JsonObject
  JsonObject A JSON object representing the Error
Top

Progress.Json.ObjectModel.JsonObject ToObject (Object, Object)

/* Converts an kay and value into a JSON Object
Parameters:
pKey Progress.Lang.Object
 
pValue Progress.Lang.Object
 
Returns Progress.Json.ObjectModel.JsonObject
  JsonObject A JSON object
Top

Progress.Json.ObjectModel.JsonObject ToObject (Stop)

/* Converts an instance of a Progress.Lang.Stop into a JSON Object
{
_errors: [
{ _errorMsg: the stop type name
_errorNum: null
_device: )
_tableName: ) If the stop is a LockConflict
_user: )
}
]
_type: if session:debug-alert
_stack: if session:debug-alert
}
Parameters:
pStop Progress.Lang.Stop
 
Returns Progress.Json.ObjectModel.JsonObject
  JsonObject A JSON object representing the Error
Top

OpenEdge.Core.IObjectArrayHolder ToObjectArray (JsonArray)

/* Converts a JSON array to an instance of a IObjectArrayHolder
Parameters:
pArray Progress.Json.ObjectModel.JsonArray
 
Returns OpenEdge.Core.IObjectArrayHolder
  IObjectArrayHolder The array holder. One is always returned.
Top

OpenEdge.Core.IObjectArrayHolder ToObjectArray (JsonArray, Class)

/* Converts a JSON array to an instance of a IObjectArrayHolder
Parameters:
pArray Progress.Json.ObjectModel.JsonArray
 
pElementType Progress.Lang.Class
 
Returns OpenEdge.Core.IObjectArrayHolder
  IObjectArrayHolder The array holder. One is always returned.
Top

Ccs.Common.Support.IPrimitiveArrayHolder ToPrimitiveArray (JsonArray)

/* Converts a JSON array to an instance of a PrimitiveArrayHolder
The first non-null element is used to infer the array's ABL type.
Objects and Arrays are returned as JSON text.
Parameters:
pArray Progress.Json.ObjectModel.JsonArray
 
Returns Ccs.Common.Support.IPrimitiveArrayHolder
  IPrimitiveArrayHolder The array holder. One is always returned.
Top

Ccs.Common.Support.IPrimitiveHolder ToScalar (JsonArray, integer)

/* This method converts a JSON array element to an instance of an IPrimitiveHolder.
If the inputs are invalid, or the index is not in range, a OE.Core.String object represeting the unknown value is returned.
Input JSON data types:
NULL -> OE.Core.String(?)
OBJECT, ARRAY -> OE.Core.String(GetJsonText)
BOOLEAN -> OE.Core.LogicalValue(<val>)
NUMBER -> if the value has a '.', OE.Core.Decimal(<val>), else OE.Core.Integer(<val>)
STRING ->
If the value looks like YYYY-MM-DD, try to parse and return OE.Core.DateHolder
If the value looks like YYYY-MM-DDTHH:MM:SS.SSS, try to parse and return OE.Core.DateTimeHolder
If the value looks like YYYY-MM-DDTHH:MM:SS.SSS+HH:MM, try to parse and return OE.Core.DateTimeTzHolder
If the value looks like a base64-encoded value (last 2 chars are ==), return as OE.Core.Memptr
If the 'looks like' or parsing fail, return OE.Core.String(<val>)
If the property value cannot be converted, an object represeting the unknown value is returned (same as NULL).
Parameters:
pArray Progress.Json.ObjectModel.JsonArray
 
pIdx INTEGER
 
Returns Ccs.Common.Support.IPrimitiveHolder
  IPrimitiveHolder The representative value
Top

Ccs.Common.Support.IPrimitiveHolder ToScalar (JsonObject, character)

/* This method converts a JSON property to an instance of an IPrimitiveHolder.
Input JSON data types:
NULL -> OE.Core.String(?)
OBJECT, ARRAY -> OE.Core.String(GetJsonText)
BOOLEAN -> OE.Core.LogicalValue(<val>)
NUMBER -> if the value has a '.', OE.Core.Decimal(<val>), else OE.Core.Integer(<val>)
STRING ->
If the value looks like YYYY-MM-DD, try to parse and return OE.Core.DateHolder
If the value looks like YYYY-MM-DDTHH:MM:SS.SSS, try to parse and return OE.Core.DateTimeHolder
If the value looks like YYYY-MM-DDTHH:MM:SS.SSS+HH:MM, try to parse and return OE.Core.DateTimeTzHolder
If the value looks like a base64-encoded value (last 2 chars are ==), return as OE.Core.Memptr
If the 'looks like' or parsing fail, return OE.Core.String(<val>)
If the property value cannot be converted, an object represeting the unknown value is returned (same as NULL).
Parameters:
pObject Progress.Json.ObjectModel.JsonObject
 
pName CHARACTER
 
Returns Ccs.Common.Support.IPrimitiveHolder
  IPrimitiveHolder The representative value


Constructor Detail
Top

JsonConverter ()

/* Default constructor.
This is private so that this class cannot be instantiated - it's intended to be used with static members only