110 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
1
answer
40
views
json_serializable: Selecting JsonConverter's at runtime
I'm looking for a solution on how I could switch what JsonConverter I am using at runtime with the package:json_serializable package. This will allow my app use DateTime objects but then convert these ...
0
votes
1
answer
74
views
How to Pass a Custom Parameter Name in a Generic Data Model with JsonSerializable in Flutter?
I have a generic data model in Flutter using the JsonSerializable. I want to pass a custom parameter name (e.g., "statistics") instead of a fixed name in the fromJson and toJson methods. ...
1
vote
1
answer
86
views
How to generate methods in `PerFieldToJson` using `json_serializable`?
Minimum reproducible code:
// foo.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore_odm/cloud_firestore_odm.dart';
import 'package:json_annotation/...
1
vote
1
answer
77
views
How to convert a Map to a List of keys
Suppose I have the following model (using freezed):
@freezed
class User with _$User {
const factory User({
required UserID id,
required List<String> categories,
}) = _User;
...
0
votes
1
answer
139
views
Nested Json Serialization Doesn't Work Event With explicitToJson: TRUE?
I am new to flutter and have been developing a small api that would pull data from a local mock database I created. The database has a nested Json within it, and no matter what I did, I can't get it ...
0
votes
1
answer
196
views
Seeking Efficient Use of json_serializable with Generics in Dart for export models in a package/library
I am currently using json_serializable with generic objects in Dart, where the generics should freezed classes (have toJson methos and fromJson constructor). I have a working implementation, but I'm ...
0
votes
1
answer
55
views
Property name and key name in JSON can be different in Flutter?
I am facing an issue in my code. I am sending an object "report" which has nested classes such as this one called 'non conformities'. Inside this I am sending some files. At moment I am ...
0
votes
2
answers
620
views
Serialize a map containing an object into JSON using Dart
I am using the json_serializable package in Dart to convert my objects to JSON so I can then store them in a SQLite database. I am struggling in converting one particular property on my class because ...
0
votes
3
answers
2k
views
Using dart Freezed with sealed classes and fromJson
The documentation of freezed is telling that we should just use the sealed classes made available in dart 3. However: it does not explain how to use it, especially in combination with fromJson. So I'm ...
0
votes
2
answers
169
views
How to properly use freezed in dart/flutter
I want to convert a Json with Freezed package in Dart/Flutter.
my json:
{"rates":{"btc":{"name":"Bitcoin","unit":"BTC","value":1.0,...
1
vote
1
answer
998
views
ArgumentError (Invalid argument: Instance of ...) when converting to Json with class as a nested list
I have a class called Groups that has a property that contains a list of Members.
To send this to Firebase, I have a GroupDto and MemberDto class that converts these values to and from the domain, and ...
0
votes
1
answer
89
views
JsonSerializable. Custom function for field, dependencing other field of current class
I want to set a value to a field depending on another field of the same class.
For example, I have classes Team and Project:
class Team {
String name;
String curator;
//etc.
}
class ...
0
votes
0
answers
296
views
Flutter, Dart: How to serialize Json to Class with nested Classes
So, this example from flutter docs
import 'package:json_annotation/json_annotation.dart';
part 'address.g.dart';
@JsonSerializable()
class Address {
String street;
String city;
Address(this.street, ...
0
votes
1
answer
167
views
Validating Json in Dart JsonSerializable and Freezed
I'm using Freezed to create data classes, and to de-serialized them from a json (with the integration with JsonSerializable).
But sometimes the json are incomplete, and the fromJson method do not ...
1
vote
2
answers
1k
views
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(...