0

I have 4 classes;

public class Class1
{
    private String id;
    private List<Class1a> class1aItems = null;

    ....
}

public class Class1a
{
    private String id;
    private String info;

    ....
}


public class Class2
{
    private String id;
    private List<Class2a> class2aItems = null;

    ...
}

public class Class2a
{
    private String id;
    private String info;

    ...
}

and i can't set the same name to the lists in Class1 and Class2.

Then, i have to map Class1 into Class2 using automapper like this:

TypeMap<Class1, Class2> typeMap = modelMapper.createTypeMap(Class1.class, Class2.class);
        typeMap.addMapping(Class1::getClass1aItems, Class2::setClass2aItems);

        Class2 class2 = modelMapper.map(class1, Class2.class);

For the main classes it works (Class1 is mapped into Class2) except for the list. Class2 have an empty class2aItems while before the mapping class1aItems was populated with 3 items.

What am I doing wrong ?

1 Answer 1

1

Try implement java.io.Serializable in your destiny Class

public class Class2 implements Serializable
{
    private String id;
    private List<Class2a> class2aItems = null;

    ...
}

public class Class2a implements Serializable
{
    private String id;
    private String info;

    ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.