publicissapient-france / selma

Selma Java bean mapping that compiles
http://selma-java.org
Apache License 2.0
213 stars 38 forks source link

Bad Code Generated For Fields with Type #170

Open chiragpatel-lsu opened 7 years ago

chiragpatel-lsu commented 7 years ago

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

slemesle commented 7 years ago

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.

chiragpatel-lsu commented 7 years ago

Does selma support overloaded setters?

On Wed, Jul 19, 2017 at 4:40 PM, slemesle notifications@github.com wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xebia-france/selma/issues/170#issuecomment-316526279, or mute the thread https://github.com/notifications/unsubscribe-auth/AZZrCviHxfgxs64H1ztDqEU7BXp_qMzaks5sPnfrgaJpZM4OXnzQ .

-- Chirag Patel Senior Software Engineer Austin, TX 318.680.9248 ChiragPatel.LSU@gmail.com

slemesle commented 7 years ago

Hi,

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

can you provide a sample code reproducing the error ?