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

JsonSerializer and XmlSerializer don't serialize DynamicObject.Type property #4

Closed
azabluda opened this issue Dec 20, 2016 · 3 comments
Assignees

Comments

@azabluda
Copy link
Contributor

I extended When_using_dynamic_object_for_complex_object_tree class with one more test

public class When_using_dynamic_object_for_complex_object_tree
{
    // ...

    public When_using_dynamic_object_for_complex_object_tree()
    {
        var originalObject = new DynamicObject()
        {
            { "DoubleValue", DoubleValue },
            { 
                "Reference", new DynamicObject(typeof(string))
                {
                    { "StringValue", StringValue },
                }
            },
        };

        serializedObject = originalObject.Serialize();
    }

    [Fact]
    public void Clone_should_contain_type_information()
    {
        var nestedObject = serializedObject["Reference"] as DynamicObject;

        (nestedObject.Type?.Type).ShouldBe(typeof(string));
    }
    
    // ...
}

It passes with BinaryFormatter, DataContractSerializer and NetDataContractSerializer, but fails with JsonSerializer and XmlSerializer.

@6bee
Copy link
Owner

6bee commented Dec 22, 2016

The issue lies in the fact that DynamicObject implements IEnumerable which apparently XmlSerializer treats as a collection only and ignores any of its actual properties. Apparently, the same is true for Json.net.

I’ll have to address this, and I’m actually tempted to get rid of the interfaces on DynamicObject since the only alternative I can think of is having a surrogate class which seems unpractical.

@6bee
Copy link
Owner

6bee commented Dec 27, 2016

Since XmlSerializer applies special behavior to IEnumerable, I had to remove this interface from DynamicObject. The only workaround I found was to implement IXmlSerializable, but this doesn't mix with DataContractAttribute.

Json.net in addition to IEnumerable also adds specific logic for types implementing IDynamicMetaObjectProvider. Hence DynamicObject is now marked with JsonObjectAttribute along with JsonIgnoreAttribute on its calculated properties.

azabluda referenced this issue Jan 9, 2017
…on.net related to specific handling of IEnumerable<> and IDynamicMetaObjectProvider
@azabluda
Copy link
Contributor Author

Works fine in 4.0.0-alpha-031. Thank you!

@6bee 6bee self-assigned this Mar 2, 2017
azabluda added a commit to azabluda/InfoCarrier.Core that referenced this issue Apr 28, 2017
Here we address two problems:
1. DynamicObject.Type property not serialized (6bee/aqua-core#4). Have to add "__ClrType" pseudo-property to each DynamicObject representing a boxed primitive value. Need to remove this workaround after the original bug is fixed.
2. Remote.Linq misinterprets a single element of type T[] as a collection of T, so we need to compensate this effect.
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