google / google/json_serializable.dart
Found more than one matching converter for `int?`.
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
my json convertor
```class JsonIntConverter extends JsonConverter {
const JsonIntConverter();
@override
int fromJson(dynamic json) {
if (json is int) {
return json;
} else {
return int.parse(json);
}
}
@override
dynamic toJson(int object) {
return object;
}
}
class JsonNullIntConverter extends JsonConverter {
const JsonNullIntConverter();
@override
int? fromJson(dynamic json) {
if (json == null) {
return null;
}
if (json is int) {
return json;
} else {
return int.parse(json);
}
}
@override
dynamic toJson(int? object) {
return object;
}
}
```
my entity
```
@JsonSerializable(converters: [const JsonNullIntConverter,const JsonIntConverter()])
class FileInfo {
@JsonKey(name: 'status')
int status;
@JsonKey(name: 'file_id')
int fileId = 0;
@JsonKey(name: 'file_name')
String? fileName;
@JsonKey(name: 'file_path')
String? filePath;
@JsonKey(name: 'file_preview_url')
String? filePreviewUrl;
@JsonKey(name: 'file_size')
int? fileSize = 0;
}
```
error
```Found more than one matching converter for `int?`.```
if i remove JsonIntConverter,JsonNullIntConverter di not gen code for int
```
FileInfo _$FileInfoFromJson(Map json) => FileInfo(
status: json['status'] as int? ?? 0,
fileId: json['file_id'] as int? ?? 0,
fileName: json['file_name'] as String?,
filePath: json['file_path'] as String?,
filePreviewUrl: json['file_preview_url'] as String?,
fileSize: json['file_size'] as int? ?? 0,
bucket: json['bucket'] as String?,
key: json['key'] as String?,
host: json['host'] as String?,
accessid: json['accessid'] as String?,
callback: json['callback'] as String?,
callbackVar: json['callback-var'] as String?,
policy: json['policy'] as String?,
signature: json['signature'] as String?,
expire: json['expire'] as String?,
);
```
Contributor guide
Assessment
This issue has not been assessed yet.