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 List<String> to a List of non-String data type #85

Open
psawmora opened this issue Nov 16, 2018 · 1 comment
Open

Mapping List<String> to a List of non-String data type #85

psawmora opened this issue Nov 16, 2018 · 1 comment

Comments

@psawmora
Copy link

psawmora commented Nov 16, 2018

I was trying to do a recursive mapping on List of Strings to a List of Some other type. For an example take the following class definitions. Classes have getters and setters set through longbok.

`

public static class EmployeeDB {

    private String bankName;

    List<Detail> details;
}

public class Detail {

private String name;
private String address;

}

public static class Source {

    private String bankName;

    List<String> names;
   
}

`

The Jmapper API was as follows.

`

JMapperAPI jMapperAPI = new JMapperAPI()
.add(mappedClass(EmployeeDB.class)
.add(global()
.excludedAttributes("details"))
.add(attribute("details").value("names"))
)
.add(mappedClass(Detail.class)
);

    Source source = new Source();
    source.setBankName("Bank-1");
    source.setNames(List.of("e-1", "e-2"));
  
   JMapper<EmployeeDB, Source> mapper = new JMapper<>(EmployeeDB.class, Source.class, jMapperAPI);
    EmployeeDB employeeDB = mapper.getDestination(source);
    System.out.println(employeeDB.getDetails().get(0).getName());

`
Here I've tried setting a recursive mapping for Detail class but haven't set any attributes as I couldn't find a proper target attribute in the String class.

When ran, I got the following exception.

Exception in thread "main" java.lang.ClassCastException: java.base/java.lang.String cannot be cast to com.ilt.cms.pm.integration.mapper.Detail

Is there any special way to map a List to List (based on the example here) ?

@psawmora
Copy link
Author

I'm using 1.6.1.CR2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant