java - BeanIO write annotated class to fixedlength -


i trying write annotated class fixedlength file beanio. classes annotated getting exception

"invalid field 'employees', in record 'team', in stream 'tm': type handler not found type 'com.mycompany.bio.employee'"

below source code

 public static void main(string[] args) {     streamfactory factory = streamfactory.newinstance();     streambuilder builder = new streambuilder("tm")             .format("fixedlength")             .parser(new fixedlengthparserbuilder())             .addrecord(com.mycompany.bio.team.class);     factory.define(builder);      employee e1 = new employee("empf1", "empl1", "developer", "1", new date());     employee e2 = new employee("empf2", "empl2", "developer", "2", new date());     team team = new team();     team.setteamname("great team");     team.getemployees().add(e1);     team.getemployees().add(e2);      beanwriter out = factory.createwriter("tm", new file("c:\\users\\user\\desktop\\tm.dat"));      out.write(team);     out.flush();     out.close(); } 

team class:

@record(minoccurs = 1) public class team { // @segment(collection = arraylist.class, minoccurs = 0, maxoccurs = integer.max_value)  segments return single line team::teamname , 2 emp records, want see 3 lines 1.teamname 2 & 3 emp info @field(ordinal = 1, length = 106) private list<employee> employees; @field(ordinal = 0, length = 10) private string teamname;  ..... } 

employee class:

@record(minoccurs=1) public class employee { @field(ordinal = 1, length = 30) private string firstname; @field(ordinal = 2, length = 30) private string lastname; @field(ordinal = 3, length = 30) private string title; @field(ordinal = 4, length = 8) private string salary; @field(ordinal = 5, format="mmddyyyy", length = 8) private date hiredate; ... } 

quick solution is:

    public static void main(string[] args) throws ioexception {     streamfactory factory = streamfactory.newinstance();     streambuilder buildercsv = new streambuilder("tm")             .format("fixedlength")             .parser(new fixedlengthparserbuilder())             .addrecord(com.mycompany.bio.team.class)             .addrecord(com.mycompany.bio.employee.class);     factory.define(buildercsv);      beanwriter out = factory.createwriter("tm", new file("c:\\users\\topsecretusername\\desktop\\tm.txt"));      employee e1 = new employee("empf1", "empl1", "developer", "1", new date());     employee e2 = new employee("empf2", "empl2", "developer", "2", new date());     team team = new team();     team.setteamname("great team");     team.getemployees().add(e1);     team.getemployees().add(e2);      out.write(team);     (employee e : team.getemployees()) {         out.write(e);     }      out.flush();     out.close();  } 

team class:

@record public class team {    @field(ordinal = 1, length = 10)    private string teamname;    private list<employee> employees = new arraylist<>(); ....} 

employee:

@record public class employee {  @field(ordinal = 1, length = 30) private string firstname; @field(ordinal = 2, length = 30) private string lastname; @field(ordinal = 3, length = 30) private string title; @field(ordinal = 4, length = 8) private string salary; @field(ordinal = 5, format="mmddyyyy", length = 8) private date hiredate; ....} 

output file content:

great team empf1                         empl1                         developer 1           20150622 empf2                         empl2                         developer 2           20150622 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -