-
Notifications
You must be signed in to change notification settings - Fork 199
Description
Version: release 0.1.0
I was trying to decode the following XML:
<GraphDataModel><root><Cell id="0"><Object as="style"/></Cell><Cell id="1" parent="0"><Object as="style"/></Cell><Cell id="B_#0" value="rootNode" vertex="1" parent="1"><Geometry _x="100" _y="100" _width="100" _height="80" as="geometry"/><Object as="style"/></Cell></root></GraphDataModel>const doc = xmlUtils.parseXml(str);
const codec = new Codec(doc);
codec.decode(doc.documentElement, this.graph.getDataModel());And got error like this:
Uncaught Error: Invalid x supplied.
at set x [as x] (Point.js:44:19)
at GraphView.updateCellState (GraphView.js:743:32)
at GraphView.validateCellState (GraphView.js:676:26)
at GraphView.validateCellState (GraphView.js:691:30)
at GraphView.validateCellState (GraphView.js:691:30)
at GraphView.validate (GraphView.js:444:58)
at ModelEditorGraph.graphModelChanged (Graph.js:429:19)
at Graph.graphModelChangeListener (Graph.js:348:18)
at GraphDataModel.fireEvent (EventSource.js:132:41)
at edit.notify (GraphDataModel.js:958:25)
After doing a lot of debugging, I found that CodecRegistry.getCodecByName(node.nodeName) does not return the default ObjectCodec for some elements (like Point, Geometry, etc... ). Therefore the decoding procedure returns the original xml element, and breaks later procedure.
I also found that if I do encoding before decoding, no error will occurs because encoding procedure uses CodecRegistry.getCodec(constructor_) which Registers a new default codec for the given constructor, if no codec has been previously defined.
My possible workaround: Manually register ObjectCodec for missing codecs:
CodecRegistry.register(new ObjectCodec(new Geometry()));
CodecRegistry.register(new ObjectCodec(new Point()));
CodecRegistry.register(new ObjectCodec(new Array()));Perhaps CodecRegistry.getCodecByName(node.nodeName) should return a default codec like CodecRegistry.getCodec(constructor_) does?