Profile Picture

Problem Serializing Custom Objects with CustomXml Format

Posted By Jason Irby 11 Years Ago

Problem Serializing Custom Objects with CustomXml Format

Author
Message
Jason Irby
questionmark Posted 11 Years Ago
View Quick Profile
Forum Member

Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 59, Visits: 77

 

We have some custom objects we attach to our diagram shape. We'd like some of the data in the custom object to be stored in a byte[]. That data can be fairly large.

We have found that when the diagram document is persisted out in CustomXml format, the serialized version of those custom objects become incredibaly large.

An simplified example of what we are attempting:

A simple info object

 

[Serializable]

public class TestInfo : ICloneable

{

private byte[] _data;

public byte[] Data

{

get { return _data; }

set { this._data = value; }

}

public virtual object Clone()

{

TestInfo info = new TestInfo();

info.Data = this.Data;

return info;

}

}

 

A simple test example

private void button1_Click(object sender, EventArgs e)

{

TestInfo info = new TestInfo();

NShape r = new NRectangleShape(0, 0, 200, 200);

this.nDrawingDocument1.ActiveLayer.AddChild(r);

r.Tag = info;

NPersistencyManager pm = new NPersistencyManager();

pm.Serializer.XmlExtraTypes = new Type[] { typeof(TestInfo)};

info.Data = File.ReadAllBytes(test3Path);

pm.PersistentDocument.Sections.Clear();

pm.PersistentDocument.Sections.Add(new NPersistentSection("Doc", this.nDrawingDocument1));

pm.SaveToFile(@"C:\TestNevronDoc.CNDX", PersistencyFormat.CustomXML, null);

}

Results

When the PersistencyManager saves out the drawing document, the size is much, much larger than expected (even for XML). I usually just have to stop it and looking at what it was doing, I see it serializing out the byte array like (truncated for brevity):

<Object typeId="80" name="Tag">

<Object typeId="81" name="Data">

<Collection>

<PrimitiveItem>2;255</PrimitiveItem>

<PrimitiveItem>2;216</PrimitiveItem>

<PrimitiveItem>2;255</PrimitiveItem>

<PrimitiveItem>2;224</PrimitiveItem>

<PrimitiveItem>2;0</PrimitiveItem>

<PrimitiveItem>2;16</PrimitiveItem>

<PrimitiveItem>2;74</PrimitiveItem>

<PrimitiveItem>2;70</PrimitiveItem>

<PrimitiveItem>2;73</PrimitiveItem>

<PrimitiveItem>2;70</PrimitiveItem>

<PrimitiveItem>2;0</PrimitiveItem>

<PrimitiveItem>2;1</PrimitiveItem>

<PrimitiveItem>2;1</PrimitiveItem>

<PrimitiveItem>2;1</PrimitiveItem>

...

Every byte in the array as a separate XML element?

 

Where as, if as a test I just use a generic .Net XMLSerializer class the Data property is serialize as a base64 incoded string like(truncated for brevity):

<TestInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<Data>/9j/4AAQSkZJRgABAQEAYABgAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGl..........

Is there anyway to have PersistencyManager serialize that byte[] property more reasonably?

 

Thanks in Advance,

Jason Irby

 

 

 

 




Threaded View



Similar Topics


Reading This Topic