Skip to content

Instantly share code, notes, and snippets.

@anithegregorian
Created November 22, 2021 08:48
Show Gist options
  • Save anithegregorian/db35e3fbd45a6b02061a70ba51adc30c to your computer and use it in GitHub Desktop.
Save anithegregorian/db35e3fbd45a6b02061a70ba51adc30c to your computer and use it in GitHub Desktop.
function CustomData(value) {
this.value = value;
}
var codec = new mxObjectCodec(new CustomData());
codec.encode = function (enc, obj) {
var node = enc.document.createElement('CustomData');
mxUtils.setTextContent(node, JSON.stringify(obj));
return node;
};
codec.decode = function (dec, node, into) {
var obj = JSON.parse(mxUtils.getTextContent(node));
obj.constructor = CustomData;
return obj;
};
mxCodecRegistry.register(codec);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment