Redstone mapper with flutter


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 {
  DataType dateType; // might be a User object

  String id;

  List<String> versions;


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.

Answered By – matanlurey

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *