1

I am trying to decode a list of integers, e.g. "[1,2,3,4]", like this

decodeJson(json, new List<int>().runtimeType)

but I am getting this error

MapperException:  UnsupportedType: List<int>. This type wasn't mapped by redstone_mapper's
transformer. See http://goo.gl/YYMou2 for more information.

Here is my pubspec.yaml

name: restonetest
description: A sample web application
dependencies:
  angular: any
  appengine: any
  browser: any
  di: any
  fp: any
  redstone: any
  redstone_mapper: any
  shelf_static: any
transformers:
- redstone_mapper
- angular:
    html_files:
    - lib/client/models/evento/evento.html

What should I do?

Edit

The actual problem appears to be with redstone_mapper transformer. If I take it out from the pubspec.yaml then it works.

Cristian Garcia
  • 9,630
  • 6
  • 54
  • 75

2 Answers2

1

This works fine for me:

import 'package:redstone_mapper/mapper.dart';
import 'package:redstone_mapper/mapper_factory.dart';

main() {
  bootstrapMapper();

  String json = "[1,2,3,4]";

  var x = decodeJson(json, new List<int>().runtimeType);
  print(x);
}

and prints

[1, 2, 3, 4]
Robert
  • 5,484
  • 1
  • 22
  • 35
1

Thanks to @luizmineo for his answer here at the Redstone Mapper's Github repository. Apparently you can just give the specific type of the list because

If the json object is an array, the decode will produce a List automatically

This line of code that appears next will work for the cased exposed in the question

decodeJson(json, int);

The trick works for any type in general.

Cristian Garcia
  • 9,630
  • 6
  • 54
  • 75