publicissapient-france/selma

Bad Code Generated For Fields with Type

chiragpatel-lsu opened this issue · 3 comments

Map
@Maps(withCustomFields = {@Field({"id", "id"}), @Field({"allergen.name", "text"})}) AllergyIntolerance toFhir(Allergy source);

Generated Code
public final ca.uhn.fhir.model.dstu2.composite.NarrativeDt asNarrativeDt(String inString) { ca.uhn.fhir.model.dstu2.composite.NarrativeDt out = null; if (inString != null) { out = new ca.uhn.fhir.model.dstu2.composite.NarrativeDt(); } return out; }

Should be
public final ca.uhn.fhir.model.dstu2.composite.NarrativeDt asNarrativeDt(String inString) { ca.uhn.fhir.model.dstu2.composite.NarrativeDt out = null; if (inString != null) { out = new ca.uhn.fhir.model.dstu2.composite.NarrativeDt(inString); } return out; }
Notice how after the if statement the value is not set on the constructor.

I am wondering if I am setting something wrong or is this a bug?

Thanks

Hi,

this sounds like a bug sure. Can you provide a sample code or PR with an integration test to reproduce this error ?
Selma, will not call a constructor with inString because it does not support this kind of mapping. It should call a setter for the string field (if it exists). Depending on your @Mapper configuration, Selma will ignore the missing setter and produce this kind of code without error.

Please give me some more, to help and fix if needed.

Hi,

if you mean inherited or overwritten setters then yes it does.

can you provide a sample code reproducing the error ?