Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type safe serialization of primitives and System.Type #378

Open
hakito opened this issue Jan 16, 2019 · 0 comments
Open

Type safe serialization of primitives and System.Type #378

hakito opened this issue Jan 16, 2019 · 0 comments

Comments

@hakito
Copy link

hakito commented Jan 16, 2019

EnsureRoundtrip emits tags for objects when needed. But it does not force emission of tags for primitives.

For example the class

class Container
{
    public object Data { get; set; } = 123L;
}

will be deserialized as string "123".

I could bypass the problem by appending a custom ChainedEventEmitter after the TypeAssigningEventEmitter.

However It was still not possible to properly deserialize the container when data was assigned an instance of System.Type. For example container.Data = typeof(long) is deserialized also as string because the SystemTypeConverter bypassed the ChainedEventEmitter and also does not emit a tag:

emitter.Emit(new Scalar(null, null, systemType.AssemblyQualifiedName, ScalarStyle.Any, true, false));

I'd suggest to add a method like WithSystemTypeTagPrefix(string) to the serialization builder classes and always emit tags when the runtime type is not equal to the declared type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants