You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This came up in #463 as a solution and finally solved my issue; therefore, I think it's worth documenting.
When you need to have both the freezed and JsonSerializer() annotations on your class, your fromJson() factory declaration MUST use block form not annotation form.
// DO THIS
@freezed
@JsonSerializable(fieldRename: FieldRename.snake)
class MapPlace with _$MapPlace {
const MapPlace._();
const factory MapPlace({
...
}) = _MapPlace;
factory MapPlace.fromJson(Map<String, dynamic> json) {
return _$MapPlaceFromJson(json);
}
}
// NOT THIS
...
factory MapPlaceLocation.fromJson(Map<String, Object?> json) =>
_$MapPlaceLocationFromJson(json);
...
I needed to use the "fieldRename" capability of the @JsonSerializer() annotation on a couple of my freezed classes. I kept getting errors like this. But once I changed to block form like described in #463 then everything worked.
lib/maps_service/model_places_nearby.g.dart:9:10: Error: '_$MapPlaceFromJson' is already declared in this scope.
MapPlace _$MapPlaceFromJson(Map<String, dynamic> json) => MapPlace(
^^^^^^^^^^^^^^^^^^
lib/maps_service/model_places_nearby.freezed.dart:178:10: Context: Previous declaration of '_$MapPlaceFromJson'.
MapPlace _$MapPlaceFromJson(Map<String, dynamic> json) {
^^^^^^^^^^^^^^^^^^
lib/maps_service/model_places_nearby.dart:35:7: Error: Can't use '_$MapPlaceFromJson' because it is declared more than once.
_$MapPlaceFromJson(json);
Thanks,
Eric
The text was updated successfully, but these errors were encountered:
This came up in #463 as a solution and finally solved my issue; therefore, I think it's worth documenting.
When you need to have both the freezed and JsonSerializer() annotations on your class, your fromJson() factory declaration MUST use block form not annotation form.
I needed to use the "fieldRename" capability of the @JsonSerializer() annotation on a couple of my freezed classes. I kept getting errors like this. But once I changed to block form like described in #463 then everything worked.
Thanks,
Eric
The text was updated successfully, but these errors were encountered: