Menu

#151 Review the possibility to support multiple CsvRecurse annotations for fields with the same type in the same bean

wont-fix
5
2022-01-06
2021-11-18
No

Hello,

There is a limitation on adding CsvRecurse on multiple fields with the same type in one bean, but I want to process recursively each of them but with specific unique headers.

public class ExampleBean {
    private String simple;

    @CsvRecurse
    private UserInfo createdBy;
    @CsvRecurse
    private UserInfo modifiedBy;
    @CsvRecurse
    private UserInfo owner;
}

public class UserInfo {
    private String firstName;
    private String lastName;

    @CsvBindByName
    private String username;

    private String primaryEmail;
}

I expect the input to be mapped to this bean could look like this:

simple,createdBy username,modifiedBy username,owner username
simple value,johndoe@mail.com, mrstone@mail.com, mrs.mason@mail.com

but I got an error: "recursive.type.encountered.twice".

Thanks.

Discussion

  • Andrew Rucker Jones

    While I understand your desire, there is a reason for this limitation. Using your example, you annotated UserInfo.username with a simple CsvBindByName, which means opencsv expects the input field in the CSV file to be named "username." You cannot now re-annotate the same bean member with the name of a different field from the CSV input.

     
  • Andrew Rucker Jones

    • status: open --> wont-fix
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.