json_serializable.dart
json_serializable.dart copied to clipboard
JsonConverter with import prefix
I have a CustomJsonConverter
defined in a separate library which i want to import using a library prefix.
import 'library.dart' as converter;
@JsonSerializable()
class MyObject {
// ....
@converter.CustomJsonConverter()
final CustomObject value;
}
but the generated code uses CustomJsonConverter.toJson
instead of including the converter.
library prefix.
Not a big problem, since i could just remove the prefix, but it would be nice if this was supported.
This is in the scope known work that just hasn't been done. Handling prefixes for core types, etc is something we also need to work on
Neat, there's already an issue. I will add my example for documentation:
I have 2 Questionnaires, one prefixed with fhir
and one without.
import 'package:fhir/r4.dart' as fhir;
Questionnaire questionnaire;
fhir.Questionnaire fhirQuestionnaire;
results in fromJson:
..fhirQuestionnaire = Questionnaire.fromJson(json['fhir_questionnaire'])
I will rename my own Questionnaire for now.
@kevmoo Have the question solved? and When?
@kevmoo this is also a big issue for me. I've been trying to resolve it but it seems that it's impossible to get the import prefix for an Element
.