0
votes

I want to use the redstone mapper to decode Json to objects. However flutter doesn't support mirrors and so I cannot initialize the mapper over the normal way with bootstrapMapper();

Therefore I looked it up, I have to use staticBootstrapMapper(...)

/**
     * initialize the mapper system.
     * 
     * This function provides a mapper implementation that
     * uses data generated by the redstone_mapper's transformer,
     * instead of relying on the mirrors API.
     * 
     */ 
    void staticBootstrapMapper(Map<Type, TypeInfo> types) {
      _staticTypeInfo = types;

      configure(_getOrCreateMapper, _createValidator);
    }

Link to source code

I dont know what I should put into the map of Map<Type, TypeInfo> types. Lets say I want to use ObjectData to transform json data to this object. But how do I have to use this initializing method? Unfortunately I didnt find an example how to use this static bootstrap manager.

class ObjectData {
  @Field()
  @NotEmpty()
  DataType dateType; // might be a User object

  @Field()
  @NotEmpty()
  String id;

  @Field()
  @NotEmpty()
  List<String> versions;
}
1
I know its not the answer of your question but my be it could help: pub.dartlang.org/packages/jaguar_serializer - Christoph Lachenicht
Flutter won't support mirrors. You'll have to gi with a code generation solution. - Günter Zöchbauer
Yep I think all of them (also /jaguar_serializer) are not working because they use mirrors and reflection. Therefore i want to use staticBootstrapMapper because it doesn't use mirrors. But I dont know how to initialize this method so that the framework translate all the static types into objects. - GreenTigerEye
jaguar should work youtube.com/watch?v=jF0kD7lxTTw look at 13:13 - Christoph Lachenicht
yep thanks its a great video ;) I will try it out - GreenTigerEye

1 Answers

1
votes

Mirrors isn't supported in Flutter, as noted above in comments.

You might want try alternative packages that don't rely on mirrors:

Of those two (and others) json_serializable looks like the easiest to get started, but might not have as many features.