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

Mapping BeanSource[] to BeanDestination[] not supported #126

Closed
Meekou opened this issue Oct 10, 2016 · 2 comments
Closed

Mapping BeanSource[] to BeanDestination[] not supported #126

Meekou opened this issue Oct 10, 2016 · 2 comments
Labels
Milestone

Comments

@Meekou
Copy link

Meekou commented Oct 10, 2016

It seems Selma does not provide native support to convert an array of BeanSource to an array of BeanDestination
But it works fine from a List<BeanSource> to a List<BeanDestination>.

Code below does not compile:

public class BeanSource {
    private int foo;

    public int getFoo() {
        return this.foo;
    }

    public void setFoo(int foo) {
        this.foo = foo;
    }
}

public class BeanDestination {
    private int foo;

    public int getFoo() {
        return foo;
    }

    public void setFoo(int foo) {
        this.foo = foo;
    }
}

public class ArrayBeanSource {
    private BeanSource beans[];

    public BeanSource[] getBeans() {
        return this.beans;
    }

    public void setBeans(BeanSource beans[]) {
        this.beans = beans;
    }
}

public class ArrayBeanDestination {
    private BeanDestination beans[];

    public BeanDestination[] getBeans() {
        return this.beans;
    }

    public void setBeans(BeanDestination beans[]) {
        this.beans = beans;
    }
}

@Mapper(withIoC = IoC.SPRING)
public interface BeanMapper {

    ArrayBeanDestination asArrayBeanDestination(ArrayBeanSource in);
}

I somehow manage to workaround the problem with an abstract mapper

@Mapper(withIoC = IoC.SPRING)
public abstract class AbstractBeanMapper {

    public abstract BeanDestination asBeanDestination(BeanSource in);

    public abstract ArrayBeanDestination asArrayBeanDestination(ArrayBeanSource in);

    public BeanDestination[] asBeanDestination(BeanSource[] in) {
        if (in == null) {
            return null;
        }
        return Arrays.stream(in).map(this::asBeanDestination).toArray(BeanDestination[]::new);
    }

}

Could it be possible for Selma to handle this natively ?
We do not always have the possibility to change the BeanSource or BeanDestination implemention.

@slemesle slemesle added the bug label Nov 24, 2016
@slemesle slemesle added this to the 1.0 Final milestone Nov 24, 2016
@slemesle
Copy link

This is fixed in master branch.

@Meekou
Copy link
Author

Meekou commented Nov 28, 2016

Thanks !

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