jmapper-framework / jmapper-core

Elegance, high performance and robustness all in one java bean mapper
http://jmapper-framework.github.io/jmapper-core
Apache License 2.0
227 stars 41 forks source link

NullPointerException in Annotation.fillMappedField #76

Open reyleo opened 6 years ago

reyleo commented 6 years ago

Issues happens when creating mapper with API and attribute has custom accessor annotation. Here is minimal Test class

import com.googlecode.jmapper.JMapper;
import com.googlecode.jmapper.annotations.JMapAccessor;
import com.googlecode.jmapper.api.JMapperAPI;
import org.junit.Assert;
import org.junit.Test;

import static com.googlecode.jmapper.api.JMapperAPI.*;
public class MinimalTest {

    public static class Source {
        String srcText;

        public String getSrcText() {
            return srcText;
        }

        public void setSrcText(String srcText) {
            this.srcText = srcText;
        }
    }

    public static class Destination {

        @JMapAccessor(set = "customSet")
        String dstText;

        public void customSet(String text) {
            this.dstText = text + " custom";
        }
        public String getDstText() {
            return dstText;
        }

        public void setDstText(String dstText) {
            this.dstText = dstText;
        }
    }

    @Test
    public void minimal_test() {

        JMapperAPI api = new JMapperAPI();
        api.add(mappedClass(Source.class)
                .add(attribute("srcText").value("dstText")));
        JMapper<Destination, Source> mapper = new JMapper<>(Destination.class, Source.class, api);
        Source src = new Source();
        src.setSrcText("A");
        Destination dst = mapper.getDestination(src);

        Assert.assertEquals("A custom", dst.getDstText());

    }
}