Einhugur Serialization Framework for Xojo

JSONSerializer Class

A class to serialize complex class structures to JSON using Einhugur JSON Parser Plugin with almost no coding needed.

Object
   JSONSerializer

class JSONSerializer

Constructors

JSONSerializerA constructor with no parameters for the JSONSerializer class.

Properties

ThrowIfMissingPropertySet this property to true if you want to throw exceptions on missing properties when deserializing.

Methods

AddKnownClassAdds known classes which is required when de-serializing polymorphic structures
DeSerializeDe-serialize's a class structure. (This variation allows for setting default text encoding to be set on read string properties)
DeSerializeDe-serialize's a class structure
SerializeSerialize's a class structure

Examples

You can fine tune your serialized data with the following attributes:

SerializeIgnore

Tells the serializer to ignore this property.

Example Usage in the Attribute editor in Xojo:

SerializeIgnore

SerializeRename

Tells the serializer to rename the property in the serialized data. for example if the Xojo property is called Y then you could serialize it as YCoord.

Example Usage in the Attribute editor in Xojo:

SerializeRename "YCoord"

SerializeArrayElementName

Defines a element name in the XML for array elements for the given property if this Attribute is not used then the element name will be Value.

Example Usage in the Attribute editor in Xojo:

SerializeArrayElementName "Employee"

SerializeArrayElementFactory
Tells the de-serialiser to use a custom class factory when constructing instances of class elements in object arrays.
(Note this attribute does nothing on non object arrays, for example it will be ignored on Integer array)

Example Usage in the Attribute editor in Xojo:

SerializeArrayElementFactory “MyCustomClassFactory"

This will make the the method called MyCustomClassFactory get called for each element of the array when the array is deserialized.

Signature of the factory method must be YourMethodName(className as String) as YourClassType where YourMethodName can be any name but must be same as you define in the attribute, and YourClassType is type of the class that you have in the array property.

SerializeOrder

Defines the order of the serialization for the given property.

Example Usage in the Attribute editor in Xojo:

SerializeOrder 2

SerializeRequired

Attribute that can optionally be put on class properties. If class property has this and the property is missing when deserializing then exception is thrown regardless of value of the ThrowIfMissingProperty.

Example Usage in the Attribute editor in Xojo:

SerializeRequired

SerializeClassInfo

Attribute that can optionally be put on object type class properties. If it is set then the property will include extra class info in the serialized data to support polymorphism. (If for example the Property is Node as Object then with extra class info enabled the class value put in it can still work even if its of type of Subclass of the object).

Example Usage in the Attribute editor in Xojo:

SerializeClassInfo

Supported Platforms:

  • MacOS X Carbon
  • MacOS X Cocoa 32 bit
  • MacOS X Cocoa 64 bit
  • Windows 32 bit
  • Windows 64 bit
  • Linux 32 bit
  • Linux 64 bit
  • Linux ARM