Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in code generation phase: reference to unexisting field #110

Closed
faustinl opened this issue Aug 11, 2016 · 1 comment
Closed

Error in code generation phase: reference to unexisting field #110

faustinl opened this issue Aug 11, 2016 · 1 comment
Labels
Milestone

Comments

@faustinl
Copy link

Hello,

it looks like that selma get confused when field's name ends with the name of the containing class.

When executed on the following classes:

public class Source {
    private String name;
    public String getName() { return name;  }
    public void setName(String field) { this.name = field; }
}

public class Target {
    public static class Bean {
        private String name;
        public String getName() { return name; }
        public void setName(String field) { this.name = field; }
    }

    // Field name suffix is equal to class name
    private Bean fieldTarget;
    public Bean getFieldTarget() { return fieldTarget; }
    public void setFieldTarget(Bean fieldTarget) { this.fieldTarget = fieldTarget; }
}

@Mapper
public interface BeanMapper {
    @Maps( withCustomFields = @Field({"name", "fieldTarget.name"}))
    Target toBean(Source b);
}

generate the following error:

[ERROR] diagnostic: ..../selma-test/src/main/java/test/selma/BeanMapper.java:11: error: Mapping custom field name from source bean test.selma.Source, setter for field fieldname is missing in destination bean test.selma.Target !
    Target toBean(Source b);
           ^
   --> Check your custom field @Field{ "fieldtarget.name", "name"}, you can add simple class name or FQCN to the longest field path  or add missing getter
@slemesle
Copy link

You can disambiguate this by specifying the FQCN or simple class name to handle this:

@Mapper
public interface BeanMapper {
    @Maps( withCustomFields = @Field({"name", "Target.fieldTarget.name"}))
    Target toBean(Source b);
}

@slemesle slemesle added the bug label Sep 20, 2016
@slemesle slemesle added this to the 1.0 Final milestone Sep 20, 2016
slemesle added a commit that referenced this issue Apr 24, 2017
Fix #110 : Error when field's name ends with the name of the containing class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants