2

I am trying to use @Group with beanio. But I keep getting this error.

org.beanio.BeanWriterException: Bean identification failed: no record or group mapping for bean class 'class com.apps.abc.transfer.test$Main' at the current position
    at org.beanio.internal.parser.BeanWriterImpl.write(BeanWriterImpl.java:81)
    at org.beanio.internal.parser.BeanWriterImpl.write(BeanWriterImpl.java:51)
    at com.surveysampling.apps.rewardbatchprocessor.avios.transfer.test.should write file(test.groovy:81)

I have tried several different ways, but nothing seems to work. Has anybody got this working?

Here is the test class in groovy: It is very important that this works. any help is appreciated.

package com.apps.abc.transfer

import org.beanio.builder.FixedLengthParserBuilder
import spock.lang.Specification
import org.beanio.*
import org.beanio.annotation.*
import org.beanio.builder.StreamBuilder

class test extends Specification
{
BeanWriter out;
def setup()
{
    StreamFactory streamFactory = StreamFactory.newInstance();
    StreamBuilder builder2 = new StreamBuilder("abc")
            .format("fixedlength")
            .parser(new FixedLengthParserBuilder())
            .addGroup(Main.class);

    streamFactory.define(builder2);
    StringWriter writer = new StringWriter()
    out = streamFactory.createWriter("abc", writer);
}

def "should write file"()
{
    given:
    Header header = new Header()
    header.name = "A"
    BatchHeader batchHeader = new BatchHeader()
    batchHeader.name = "B"

    BatchDetail batchDetail = new BatchDetail()
    batchDetail.name = "C"

    BatchDetail batchDetail2 = new BatchDetail()
    batchDetail2.name = "E"

    BatchFooter batchFooter = new BatchFooter()
    batchFooter.name = "F"

    Batch batch = new Batch()
    batch.batchHeader = batchHeader
    batch.batchFooter = batchFooter
    ArrayList<BatchDetail> arrayList = new ArrayList<>()
    arrayList.add(batchDetail)
    arrayList.add(batchDetail2)
    batch.details = arrayList

    Main main = new Main()
    main.header = header
    main.batch = batch

    when:
    out.write(main)

    then:
    println("out : " + out)
}

@Group
static class Main {
    @Record
    public Header header;
    @Group
    public Batch batch;
}

static class Header {
    @Field(at=0, rid=true, literal="H", length = 1 )
    public String type;
    @Field(at=1, length = 1)
    public String name;
}

static class Batch {
    @Record(order=1, maxOccurs=1)
    public BatchHeader batchHeader;
    @Record(order=2)
    public List<BatchDetail> details;
    @Record(order=3, maxOccurs=1)
    public BatchFooter batchFooter;
}

static class BatchHeader {
    @Field(at=0, rid=true, literal="BH", length = 2)
    public String type;
    @Field(at=1, length = 1)
    public String name;
}

static class BatchDetail {
    @Field(at=0, rid=true, literal="BD", length = 2)
    public String type;
    @Field(at=1, length = 1)
    public String name;
}

static class BatchFooter {
    @Field(at=0, rid=true, literal="BF", length = 2)
    public String type;
    @Field(at=1, length = 1)
    public String name;
}

}

Thanks

user1860447
  • 1,316
  • 8
  • 25
  • 46

0 Answers0