simple_json_mapper 0.1.4 simple_json_mapper: ^0.1.4 copied to clipboard
Classes and helper functions that support JSON code generation and serialization via the `simple_json` package.
import 'package:simple_json_mapper/simple_json_mapper.dart';
void main() {
// The registration is normally done automatically by the generator (simple_json package)
JsonMapper.register(JsonObjectMapper<Test>(
(map) => Test(
name: map['name'] as String,
),
(instance) => {
'name': instance.name,
},
));
final jsonStr = JsonMapper.serialize(Test(name: 'Blah'));
print('Serialized JSON:');
print(jsonStr);
print('\nDeserialized and re-serialized JSON:');
print(JsonMapper.serialize(JsonMapper.deserialize<Test>(jsonStr)));
}
@JsonObject()
class Test {
const Test({this.name});
final String name;
}