Flutter/Dart JSON and serialization of an existing library class
560
You can explicitly specify which methods of LatLng should be used for serialization using JsonKey annotation:
@JsonSerializable()
class Place {
Place({
this.address,
this.coordinates,
});
final String address;
@JsonKey(fromJson: LatLng.fromJson, toJson: jsonEncode)
final LatLng coordinates;
}
Author by
Marco
Updated on December 17, 2022Comments
-
Marco over 1 year
I have a class:
import 'package:google_maps_flutter/google_maps_flutter.dart'; class Place { Place({ this.address, this.coordinates, }); final String address; final LatLng coordinates; }
LatLng
is a class of google_maps_flutter. How can I make myPlace
class serializable usingjson_annotation
andjson_serializable
?Thank you very much!