json_serializable.dart icon indicating copy to clipboard operation
json_serializable.dart copied to clipboard

JsonConverter with import prefix

Open hpoul opened this issue 3 years ago • 4 comments

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.

hpoul avatar Jul 30 '20 09:07 hpoul

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

kevmoo avatar Jul 30 '20 14:07 kevmoo

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.

nstrelow avatar Apr 22 '21 18:04 nstrelow

@kevmoo Have the question solved? and When?

mxdneu avatar Mar 29 '22 08:03 mxdneu

@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.

via-guy avatar Apr 12 '22 17:04 via-guy