xmapper 1.0.5 xmapper: ^1.0.5 copied to clipboard
A starting point for Dart libraries or applications.
example/xmapper_example.dart
import 'package:xmapper/xmapper.dart';
class LoginForm {
late String pubKey;
late String name;
late String avatar;
late String invitationCode;
late int canSearch;
LoginForm(
{required this.pubKey,
required this.name,
required this.avatar,
this.invitationCode = '',
this.canSearch = 0});
@override
String toString() => 'User($pubKey name:$name, avatar:$avatar)';
}
class UserInfo {
late String userId;
late String name;
late String avatar;
late String number;
late int canSearch;
UserInfo(
{required this.userId,
required this.name,
required this.avatar,
required this.number,
required this.canSearch});
}
void main() {
final json = '''{
"pub_key": "03e4716fb1db615cfd5d776e25d6e7e074fbe201c04b5b4aee9922d3c1cec123bc",
"name": "Alice",
"avatar": "Girl",
"can_search": 0
}''';
final obj = jsonToObject<LoginForm>(json);
print('obj: $obj');
final resp = UserInfo(
userId: obj!.pubKey,
name: obj.name,
avatar: obj.avatar,
number: '001',
canSearch: 0);
final map = objectToJson<UserInfo>(resp);
print(map);
}