1

I'm using beanio to parse a fixed length content (single string line). I want to use annotation based configuration, but it does not work.

What might wrong with the following code?

        StreamBuilder builder = new StreamBuilder("s1").addRecord(MyRecord.class);
        StreamFactory factory = StreamFactory.newInstance();
        factory.define(builder);

        Unmarshaller unmarshaller = factory.createUnmarshaller("s1");
        unmarshaller.unmarshal("123ASD");

@Record(minOccurs = 1, maxOccurs = 1)
public class MyRecord {

    @Field(at = 1, length = 3, minOccurs = 1)
    private String number;

    @Field(at = 4, length = 3, minOccurs = 1)   
    private String text;
}


org.beanio.InvalidRecordException: Invalid 'myRecord' record
 ==> Invalid 'number':  Expected minimum 1 occurrences
 ==> Invalid 'text':  Expected minimum 1 occurrences
    at org.beanio.internal.parser.UnmarshallingContext.validate(UnmarshallingContext.java:200)
    at org.beanio.internal.parser.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:204)
    at org.beanio.internal.parser.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:89)
membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

6

I was missing the following:

new StreamBuilder("s1").format("fixedlength").addRecord(MyRecord.class);
membersound
  • 81,582
  • 193
  • 585
  • 1,120