Object Serialization?

sclytrack sclytrack at ars.com
Tue Apr 24 14:30:41 PDT 2012


On 04/24/2012 08:50 PM, Jacob Carlborg wrote:
> On 2012-04-24 18:42, dcoder wrote:
>> Hello.
>>
>> I'm probably not looking hard enough, but.... Do we have any standard
>> d-library for serializing an object/object tree into -for example- an
>> xml file?
>>
>> thanks.
>
> You can have a look at Orange:
>
> https://github.com/jacob-carlborg/orange
>
> Tutorials:
>
> http://dsource.org/projects/orange/wiki/Tutorials
>
> API reference:
> http://dl.dropbox.com/u/18386187/orange_docs/orange.serialization.Serializer.html
>
>

Does it automatically pick everything to serialize?

How would you make it more selective?

struct Me
{
	int x;
	int y;
}

serialize x but not y.

Would you have to create a custom serializer?

If so I would like to see an example with the custom serializer and 
deserializer that only does the x.


>     Basic Example
>     Serialize Through Base Class
>     Register Serializer?


There is no register serializer example.


> 277 	    private void serializeStruct (T) (T value, string key, Id id)
> 278 	    {
> 279 	        string type = T.stringof;
> 280 	
> 281 	        triggerEvents(serializing, value, {
> 282 	            archive.archiveStruct(type, key, id, {
> 283 	                if (type in serializers)
> 284 	                {
> 285 	                    auto wrapper = getSerializerWrapper!(T)(type);
> 286 	                    wrapper(value, this, key);
> 287 	                }
> 288 	
> 289 	                else
> 290 	                {
> 291 	                    static if (isSerializable!(T))
> 292 	                        value.toData(this, key);
> 293 	
> 294 	                    else
> 295 	                        objectStructSerializeHelper(value);
> 296 	                }
> 297 	            });
> 298 	        });
> 299 	    }


I assume that the wrapper is the custom serializer that can be registered.

Then there is the toData that a struct can have, basically
member functions that do the serialization. Priority is
given to the registered serializer over the member functions.

And the last one. ObjectStructSerializerHelper is more a default
serializer if none is registered or doesn't have the correct
isSerializable member functions.
ObjectStructSerializerHelper(T) (T .....)


Just browsing, I haven't downloaded anything.






More information about the Digitalmars-d-learn mailing list