Questions tagged [json-serializable]
102 questions
2
votes
1 answer
Could not generate toJson code for because of type
When attempting to generate my freezed data models with the toJson function i get the following error.
Could not generate toJson code for merchants because of type Merchant.
This started happening in Flutter 2.0 and up. The type is defined and…

Filled Stacks
- 4,116
- 1
- 23
- 36
2
votes
3 answers
Flutter json_serializable models error: Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast
I'm trying to fetch data from server in flutter and I'm using json_serializable for my data model.
I successfully get the data, but when it's time to convert the json in a data list I get this error: Unhandled Exception: type 'Null' is not a…

Daitarn
- 109
- 1
- 15
2
votes
0 answers
flutter retrofit generator - error in retrofit generated file
I'm using retrofit in my flutter application and I'm using json_serialzable as well to generate model classes. here is my pubspec:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
get: ^3.24.0
flutter_custom_clippers: ^1.1.2
…

M.R.M
- 540
- 1
- 13
- 30
2
votes
0 answers
What is the best way to use json_serializable with generics?
I'm trying to achieve something like this without a lot of higher-level codes, and customizations. Will be okay if the solution works really well on cases of deeply nested T values, even if it involves writing a lot of higher-level and customized…

Frenco
- 1,299
- 1
- 8
- 25
1
vote
2 answers
How to serialize all fields in Dart enhanced enums?
I am using Flutter Freezed package which in turn uses Dart json_serialize package.
I have this Dart enhanced enum with 2 fields:
enum WorkingMode {
mix(type: 1, name: "mix"),
parallel(type: 2, name: "parallel"),
sequential(type: 3, name:…

rocotocloc
- 418
- 6
- 19
1
vote
0 answers
Dart json serializable fails with custom builder and build.yaml file
I am currently developing my own code generator using the source_gen library in dart as a separate library.
At first this is the build.yaml file I used for it:
builders:
fields_generator:
import: "package:sculptor/fields_builder.dart"
…

Koren Minchev
- 81
- 1
- 1
- 7
1
vote
0 answers
How can I run both json_serializable and my custom builder?
package:my_custom_type_generator
build.yaml
builders:
extractTypes:
import: "package:my_custom_type_generator/builder.dart"
builder_factories: ["extractTypes"]
build_extensions: {'$lib$': ['extracted-types.json']}
build_to: source
…

natebot13
- 167
- 3
- 11
1
vote
1 answer
flutter: json_serializable how set converter globally
How can I set a converter globally to replace the buildin datetime for example?
this does not appear in the documentation
https://pub.dev/packages/json_serializable
replace the datetime converter with a custom one globally for all classes

Gemu
- 409
- 4
- 4
1
vote
1 answer
getting error when adding json_serializable
I added json serializabe in my pubspec.yaml and getting below error :
Bad state: Could not parse the options provided for json_serializable.
Unrecognized keys: [super-parameters, enhanced-enums]; supported keys: [any_map, checked, constructor,…

Abhishek kapoor
- 23
- 3
1
vote
2 answers
Is there a way to return different key names for toJson and fromJson methods, json_serializable
Is it possible to use json_serializable and have different key names for same field for toJson and fromJson.
ex json-data:
{
"idUser": 123,
/// some other fields
}
incoming json_data from another APIs
{
"id" : 123,
/// some other…

Mehmet Karanlık
- 237
- 1
- 10
1
vote
0 answers
json_serializable: Problems generating classes when complexe object in constructor
When extending a class and serializing a complexe object I get some problems. Ist seems the problem only existing when extending and having the complexe object in the constructor:
import 'package:json_annotation/json_annotation.dart';
part…

derChris
- 726
- 8
- 19
1
vote
2 answers
Problem when converting a JSON list in Flutter (My model is not a subtype of type 'Map' in type cast)
I have a problem when converting my json to my model in Flutter.
I would like to access the 'body' list in order to then display the list containing 'children'.
I am trying to do it the way I already know and never failed me, now I have an…

Jarosław Gawlik
- 21
- 4
1
vote
1 answer
How do I set up a nested field in a Cloud Firestore database using JSONserializable in flutter
I have set up two of the Collections in My Cloud Firestore database in Flutter using JSONSerializable. This is shown below
models.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:json_annotation/json_annotation.dart';
part…

Leonard
- 91
- 10
1
vote
1 answer
Dart parse json map with json_serializable, but with the key
Suppose I have the following json (structured as ):
{
'A1': {'name': 'a'},
'B2': {'name': 'b'}
}
and I want to parse it to this class (notice that I use the key as the id for that user), using the fromJson factory method,…

user6097845
- 1,257
- 1
- 15
- 33
1
vote
3 answers
Renaming Flutter Freezed field names to snake, pascal,kebab or anothing along those lines
Posting this question to answer it myself. Hope this helps someone.
The problem: Generating code with flutter freezed but changing the to and from json field names to a specific renaming pattern.

Mu'aaz Joosuf
- 103
- 1
- 9