On Wednesday, 6 June 2018 at 16:34:52 UTC, Jacob Carlborg wrote:
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
I did register the main derived type and everything seems to
work. Why do I have to reset the registered types?
I still can't have a void* in my class though ;/ My exact code is
@nonSerialized void* ptr;
commenting out passes, else I get the errors
\orange\serialization\Serializer.d(975): Error: expression
`*value` is `void` and has no value
\orange\serialization\Serializer.d(1605): Error: template
instance
`orange.serialization.Serializer.Serializer.serializePointer!(inout(void)*)` error instantiating
\orange\serialization\Serializer.d(1698): instantiated
from here: `objectStructSerializeHelper!(inout(Item))`
\orange\serialization\Serializer.d(1616): instantiated
from here: `serializeBaseTypes!(item)`
\orange\serialization\Serializer.d(261): instantiated from
here: `objectStructSerializeHelper!(item)`
\orange\serialization\Serializer.d(247): instantiated from
here: `downcastSerialize!(item)`
main.d(50): instantiated from here: `register!(item)`
\orange\serialization\Serializer.d(1609): Error: template
instance
`orange.serialization.Serializer.Serializer.serializeInternal!(inout(void*))` error instantiating
\orange\serialization\Serializer.d(1698): instantiated
from here: `objectStructSerializeHelper!(inout(Item))`
\orange\serialization\Serializer.d(1616): instantiated
from here: `serializeBaseTypes!(item)`
\orange\serialization\Serializer.d(261): instantiated from
here: `objectStructSerializeHelper!(item)`
\orange\serialization\Serializer.d(247): instantiated from
here: `downcastSerialize!(item)`
main.d(50): instantiated from here: `register!(item)`
\orange\serialization\Serializer.d(1491): Error: new can only
create structs, dynamic arrays or class objects, not `void`'s
\orange\serialization\Serializer.d(1653): Error: template
instance
`orange.serialization.Serializer.Serializer.deserializePointer!(void*)` error instantiating
\orange\serialization\Serializer.d(1709): instantiated
from here: `objectStructDeserializeHelper!(Item)`
\orange\serialization\Serializer.d(1688): instantiated
from here: `deserializeBaseTypes!(item)`
\orange\serialization\Serializer.d(264): instantiated from
here: `objectStructDeserializeHelper!(item)`
\orange\serialization\Serializer.d(247): instantiated from
here: `downcastSerialize!(item)`
main.d(50): instantiated from here: `register!(item)`
changing void* ptr to int* ptr and everything works so this is an
issue in orange.
when changing to int it serializes to
<null type="inout(int)*" key="ptr"/>