redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Redstone running in the Editor vs Redstone running in Dartium #56

Closed cgarciae closed 9 years ago

cgarciae commented 9 years ago

While trying to share code on both server and client, I ended up writing classes with a structure like this

class A
{
    @Field()
    C f = new C();
}

class B extends A
{
    @Field()
    D f = new D();
}

class C
{
    @Field()
    String s = "C";
}

class D extends C
{
    @Field()
    String s = "D";
}

where A and C are general version of some classes, B and D are browser or server specific. When I run this code by serving it via Run in Dartium

String s;
    print (s = encodeJson(new B()));
    print (decodeJson(s, B));

I get

{"f":{"s":"D"}}
Instance of 'B'

as expected. But when the index.html function is served by Redstone and executes the main function I get

{"f":{"s":"D"}}
Exception: MapperException: B#f: type 'C' is not a subtype of type 'D' of 'value'. 
package:redstone_mapper/mapper_factory.dart:358<anonymous closure> 
package:redstone_mapper/mapper_factory.dart:358_TypeDecoder@529463379.convert 
package:redstone_mapper/src/mapper_impl.dart:32GenericTypeCodec.decode 
package:redstone_mapper/mapper.dart:321decodeJson 
package:redstone_mapper/mapper.dart:68main

It encodes correctly to JSON but fail to decode to a type B.

luizmineo commented 9 years ago

Thanks for reporting this! It seems that mapper isn't handling the property overriding correctly. I'll take a better look at this and let you know.

luizmineo commented 9 years ago

Fixed in redstone_mapper v0.1.10