Orange serializer/deserializer

Jacob Carlborg doob at me.com
Wed Jun 6 16:34:52 UTC 2018


On 2018-06-05 20:14, InfiniteDimensional wrote:
> I'm also having some issue now when I changed a type from using a class 
> to using it's base interface
> 
> Unhandled exception: 
> orange.serialization.SerializationException.SerializationException The 
> object of the static type "const(ItemInterface)" have a different 
> runtime type (Item) and therefore needs to either register its type or 
> register a serializer for its type "Item". at 
> ..\..\..\orange\serialization\SerializationException.d(25)
> 
> Item inherits from ItemInterface.
> 
> I was storing a list of Items and changed it to store ItemInterface
> 
> Item[] -> ItemInterface[]
> 
> and this is when the error happened.
> 
> Of course, I'd expect the interface not being serializable(although, 
> maybe @properties should be?) it would be nice if it would store the 
> actual type in it's place(an Item). Else, this prevents me from using 
> interfaces.

D doesn't support any runtime reflection (or very little). All 
reflection is done at compile time, i.e. getting all the fields. If the 
static type and the dynamic type differs Orange cannot properly 
serialize the dynamic type. For that to work you need to register all 
dynamic types that are expected to be serialized through a base class or 
interface. See this example [1].

[1] 
https://github.com/jacob-carlborg/orange/blob/master/tests/BaseClass.d#L73

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list