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.
While trying to share code on both server and client, I ended up writing classes with a structure like this
where
A
andC
are general version of some classes,B
andD
are browser or server specific. When I run this code by serving it viaRun in Dartium
I get
as expected. But when the
index.html
function is served by Redstone and executes themain
function I getIt encodes correctly to JSON but fail to decode to a type
B
.