mapper 0.1.1 copy "mapper: ^0.1.1" to clipboard
mapper: ^0.1.1 copied to clipboard

outdated

library converts map to object and object to map

example/main.dart

import 'package:mapper/mapper.dart';

class BoolParser extends Parser {
  bool decode(val) {
    if (val is int) {
      return val == 1;
    }
    return null;
  }

  int encode(val) {
    if (val is bool) {
      return val == true ? 1 : 0;
    }
    return null;
  }
}

class Simple {
  String strProp;
  int intProp;
  bool boolProp;
  double doubleProp;
}

const Map<String, dynamic> simple = const {
  "strProp": "val",
  "intProp": 13,
  "boolProp": 1,
  "doubleProp": 12.4,
};

main() {

    addParser('bool', new BoolParser());

    Simple obj = decode<Simple>(simple);

    obj.strProp; // val
    obj.intProp; // 13
    obj.boolProp; // true, was 1
    obj.doubleProp; // 12,4

    Map<String, dynamic> simple2 = encode(obj);

    simple2['strProp'] == simple['strProp']; // true
    simple2['intProp'] == simple['intProp']; // true 
    simple2['boolProp'] == simple['boolProp']; // true
    simple2['doubleProp'] == simple['doubleProp']; // true
}
1
likes
0
pub points
42%
popularity

Publisher

unverified uploader

library converts map to object and object to map

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on mapper