redstone-dart / redstone

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

Annotations in abstract classes confuse Mapper #88

Open cgarciae opened 9 years ago

cgarciae commented 9 years ago

I have this hierarchy of classes (here simplified). Once Ref was a normal class but not its abstract, and as you see it has a @Field() annotation.

class Resp
{
    @Field() String error;
}

class DbObj extends Resp
{
    @Id() String id;
}

abstract class Ref extends DbObj
{
    @Field() String get href;
}

abstract class Vista extends Ref
{
    String get icon;
}

class NormalVista extends Ref implements Vista
{
    @Field() String get icon => "algo";
    @Field() String get href => "someHost/$id"; 
}

For some strange reason when encoding NormalVista I was getting href with the id included but not the id field itself in the JSON. It had to be there because href showed it, but the mapper wasn't including it.

The error is solved by removing the @Field() annotation from href in Ref, but its not obvious because in many cases it works, just that in this particular setup it doesn't.