I’m pleased to announce the release of my MIT licensed open source EncodeKit module.
About
EncodeKit is a module for encoding and decoding Xojo objects for storage and transmission. It exposes two classes: JSONEncoder
and JSONDecoder
which are capable of serialising and deserialising almost any Xojo class with little or no input from you.
Usage
Firstly, drop the EncodeKit
module into your project.
Before you can encode a custom class, you must first register it with EncodeKit.
There is no need to register Xojo primitives or other common built-in classes such as
Dictionary, FolderItem and DateTime as they are handled internally.
To register a class called MyClass
:
EncodeKit.RegisterClass GetTypeInfo(MyClass)
To encode an instance of MyClass
:
Var encoder As New EncodeKit.JSONEncoder
Var c1 As New MyClass
Var json As String = encoder.Encode(c1)
To decode an instance of MyClass
:
Var decoder As New EncodeKit.JSONDecoder
Var c1 As MyClass = decoder.Decode(json)
Credit
This is essentially a modern port of @Kem_Tekinay proof-of-concept Serializer_MTC class:
EncodeKit
differs in the following ways:
- Separate encoder and decoder classes.
- API 2.0.
- Removed all references to
Xojo.Data
andXojo.Core
namespaces. - Removed the need for
Text
andAuto
datatypes. - Removed support for
Date
- Added support for
DateTime
,TimeZone
andFolderItem
encoding - Fixed all deprecations
Happy to take pull requests and suggestions.