Questions tagged [json-serializable]
102 questions
3
votes
2 answers
How to serialize private fields in json-serializable?
Minimal reproducible code:
@JsonSerializable()
class A {
final int _x;
A(int x) : _x = x;
factory A.fromJson(Map json) => _$AFromJson(json);
}
Note:
I don't want to make my private field _x public or define a public x…

iDecode
- 22,623
- 19
- 99
- 186
3
votes
1 answer
How to ignore null value toJson using freezed?
I've tried to create a profile model like this; fromJson looks good, but I have a problem with toJson:
@Freezed(
fromJson: true,
toJson: true,
map: FreezedMapOptions.none,
when: FreezedWhenOptions.none,
)
class ProfileAttribute with…

Afdal
- 501
- 9
- 19
3
votes
2 answers
Writing abstract classes while using Freezed
I can't seem to understand how to make abstract classes and their subclasses work properly with Freezed. Specifically, I need to define an abstract super-class with some to-override getters; the subclasses will need to override the getters, while…

venir
- 1,809
- 7
- 19
3
votes
3 answers
Freezed & json_serializable handling parsing error
I'm looking for a general solution for handling parsing errors of complex (nested + fields of Any type) objects using Freezed and json_serializable.
It should use the default value in case a field can't be parsed, and not compromise the whole…

deniskrr
- 952
- 1
- 6
- 12
3
votes
2 answers
Unable to generate fromJson() and toJson() for generics using freezed package
We are trying to create a generic Category class. At the time being, we are unsure whether category will have integer or UUID as key. Hence, we need the id to be generic for now. All works fine. However, we are unable to generate the fromJson() and…

Ariel
- 2,471
- 1
- 26
- 43
3
votes
1 answer
Custom json converter with freezed without a wrapper class
I'm using the freezed package to work with immutable models and make use of the built-in feature for json serialization by the json_serializable package. I have a simple User class/model with different union types (UserLoggedIn, UserGeneral,…

kounex
- 1,555
- 4
- 12
3
votes
1 answer
Using firestore with json_serializable after nullsafety
i'm using json_serializable and firestore. json_serializable creates a factory method with Map as parameter but after nullsafety changes, firestore start to return a Map? as document data and now i can't call…

Caio Granero
- 71
- 2
3
votes
3 answers
Shortcut for generating json_serializable (Flutter/Dart plugin) boilerplate codes in Android Studio
json_serializable plugin of Dart, does a great job of automatically generating some error prone and cumbersome parts of code, in exchange for some boilerplate: two methods, one annotation, and one reference to the generated file.
import…

Ashkan Sarlak
- 7,124
- 6
- 39
- 51
2
votes
1 answer
How to dynamically pass the T.fromJson() to Flutter class with List of ?
I'm working on the ApiResponse class of my Flutter project and this class needs a T data attribut.
I want to use JsonSerializable to generate the fromJson() method but this error appears when I tried to :
ListResponse _$ListResponseFromJson

YannMLD
- 21
- 2
2
votes
1 answer
Is there a build_extensions rule in build.yaml to output all generated Flutter models in a common directory?
I am trying to create a build_extensions rule in build.yaml for builders freezed and json_serializable to output all generated models in the directory lib/generated/model, irrespective of their original location that matches lib/**/*.dart.
What I…

Deniss Zerkalijs
- 88
- 1
- 6
2
votes
0 answers
How to pass a FireStore DocumentSnapshot to json_serializable fromJson?
I am trying to pass a Firebase / Firestore DocumentSnapshot to a json_serializable fromSnapshot, but having some issues. I found some sample code referenced here FireStore fromSnapshot vs fromMap for reading DocumentSnapshot? from a now defunct…

giorgio79
- 3,787
- 9
- 53
- 85
2
votes
2 answers
How to use FreezedUnionCase.snake for model class
I am using freezed package as a code generator. My response from API as shown below,
first_name,
last_name,
etc..,
And I am defining my model class like this,
firstName,
lastName,
etc..,
If I use @JsonKey(name: 'first_name') then it works but I…

Hemal Moradiya
- 1,715
- 1
- 6
- 26
2
votes
1 answer
Methods on JsonSerializable classes causing error
When I add the getter color below, it doesn't create fromJson method anymore. I get this error when I run my app:
Error: Method not found: 'Alert.fromJson'.
How come? I thought @JsonKey(ignore: true) would ignore it? Can I not put methods on…

BeniaminoBaggins
- 11,202
- 41
- 152
- 287
2
votes
1 answer
Convert DateTime Type to ISODate MongoDB with json_serializable flutter package
everyone i am using MongoDB as my backend , i don't have any clues how can i convert DateTime type to ISODate MongoDB , i try to look through document and searching , i can't find anything about it , do you have any idea about this ? thank in…

Heng YouSour
- 133
- 1
- 11
2
votes
1 answer
flutter pub run build_runner build --delete-conflicting-outputs run failed in github action
I want to run this command in github action to generate json seriable files in flutter(2.x), i am using json_serializable lib:
flutter pub run build_runner build --delete-conflicting-outputs
but this command run failed and I did not found any error…

Dolphin
- 29,069
- 61
- 260
- 539