simple_json_mapper 1.1.1 simple_json_mapper: ^1.1.1 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>(
(mapper, map) => Test(
name: map['name'] as String,
),
(mapper, 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;
}