// Path: copybook4java/src/main/java/com/nordea/oss/copybook/CopyBookSerializer.java
// public class CopyBookSerializer {
//     private CopyBookMapper serializer;
// 
//     public CopyBookSerializer(Class<?> type) {
//         this(type, false);
//     }
// 
//     public CopyBookSerializer(Class<?> type, boolean debug) {
//         this(type, null, debug);
//     }
// 
//     public CopyBookSerializer(Class<?> type, Class<CopyBookMapper> mapper, boolean debug) {
//         CopyBookParser parser = new CopyBookParser(type, debug);
//         try {
//             if(mapper != null) {
//                 serializer = mapper.getDeclaredConstructor().newInstance();
// 
//             } else {
//                 serializer = parser.getSerializerClass().getDeclaredConstructor().newInstance();
//             }
//             serializer.initialize(parser.getConfig());
// 
//         } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
//             throw new CopyBookException("Failed to load Serialization class("+ parser.getSerializerClass().getSimpleName() +")", e);
//         }
//     }
// 
//     public <T> byte[] serialize(T obj) {
//         return serializer.serialize(obj);
//     }
// 
//     public <T> T deserialize(byte[] bytes, Class<T> type) {
//         return serializer.deserialize(bytes, type);
//     }
// 
//     public <T> T deserialize(InputStream inputStream, Class<T> type) throws IOException {
//         return deserialize(ByteUtils.toByteArray(inputStream), type);
//     }
// 
//     public List<CopyBookException> getErrors() {
//         return null; // TODO: Implement depending on errorValue
//     }
// 
//     public int getMinRecordSize() {
//         return serializer.getMinRecordSize();
//     }
// 
//     public int getMaxRecordSize() {
//         return serializer.getMaxRecordSize();
//     }
// 
// }


import com.nordea.oss.copybook.CopyBookSerializer;
import com.nordea.oss.copybook.annotations.CopyBook;
import com.nordea.oss.copybook.annotations.CopyBookLine;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
        byte[] testBytes = serializer.serialize(test);
        assertEquals(2 + 8 * test.fields.length, testBytes.length);
        StringArrayToStringArrayDependingInOn test2 = serializer.deserialize(testBytes, StringArrayToStringArrayDependingInOn.class);
        assertArrayEquals(test.fields, test2.fields);
    }

    @CopyBook(type = FullMapper.class)
    public static class TwoStringArrayToStringArrayDependingOn {
        @CopyBookLine("02 FIELDSCOUNT PIC 9(2).")
        private int xfields1;
        @CopyBookLine("02 FIELDSCOUNT PIC 9(2).")
        private int xfields2;
        @CopyBookLine("02 FIELDS OCCURS 0 TO 10 TIMES PIC X(8) DEPENDING ON FIELDSCOUNT.")
        private String[] fields1;
        @CopyBookLine("02 FIELDS OCCURS 0 TO 10 TIMES PIC X(8) DEPENDING ON FIELDSCOUNT.")
        private String[] fields2;
    }

    @org.junit.Test
    public void twoStringArrayToStringArrayDependingOnTest() throws Exception {
        CopyBookSerializer serializer = new CopyBookSerializer(TwoStringArrayToStringArrayDependingOn.class);
        TwoStringArrayToStringArrayDependingOn test = new TwoStringArrayToStringArrayDependingOn();
        test.fields1 = new String []{ "test", "test2" };
        test.fields2 = new String []{ "tset", "2tset" };
        test.xfields1 = test.fields1.length;
        test.xfields2 = test.fields2.length;
        byte[] testBytes = serializer.serialize(test);
        assertEquals(2 + 2 + 8 * test.fields1.length + 8 * test.fields2.length, testBytes.length);
        TwoStringArrayToStringArrayDependingOn test2 = serializer.deserialize(testBytes, TwoStringArrayToStringArrayDependingOn.class);
        assertArrayEquals(test.fields1, test2.fields1);
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/CopyBookSerializer.java
// public class CopyBookSerializer {
//     private CopyBookMapper serializer;
// 
//     public CopyBookSerializer(Class<?> type) {
//         this(type, false);
//     }
// 
//     public CopyBookSerializer(Class<?> type, boolean debug) {
//         this(type, null, debug);
//     }
// 
//     public CopyBookSerializer(Class<?> type, Class<CopyBookMapper> mapper, boolean debug) {
//         CopyBookParser parser = new CopyBookParser(type, debug);
//         try {
//             if(mapper != null) {
//                 serializer = mapper.getDeclaredConstructor().newInstance();
// 
//             } else {
//                 serializer = parser.getSerializerClass().getDeclaredConstructor().newInstance();
//             }
//             serializer.initialize(parser.getConfig());
// 
//         } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
//             throw new CopyBookException("Failed to load Serialization class("+ parser.getSerializerClass().getSimpleName() +")", e);
//         }
//     }
// 
//     public <T> byte[] serialize(T obj) {
//         return serializer.serialize(obj);
//     }
// 
//     public <T> T deserialize(byte[] bytes, Class<T> type) {
//         return serializer.deserialize(bytes, type);
//     }
// 
//     public <T> T deserialize(InputStream inputStream, Class<T> type) throws IOException {
//         return deserialize(ByteUtils.toByteArray(inputStream), type);
//     }
// 
//     public List<CopyBookException> getErrors() {
//         return null; // TODO: Implement depending on errorValue
//     }
// 
//     public int getMinRecordSize() {
//         return serializer.getMinRecordSize();
//     }
// 
//     public int getMaxRecordSize() {
//         return serializer.getMaxRecordSize();
//     }
// 
// }


// Path: copybook4java/src/test/java/com/nordea/oss/copybook/serializers/CopyBookMapperFullTest.java
import com.nordea.oss.copybook.CopyBookSerializer;
import com.nordea.oss.copybook.annotations.CopyBook;
import com.nordea.oss.copybook.annotations.CopyBookLine;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

        byte[] testBytes = serializer.serialize(test);
        assertEquals(2 + 8 * test.fields.length, testBytes.length);
        StringArrayToStringArrayDependingInOn test2 = serializer.deserialize(testBytes, StringArrayToStringArrayDependingInOn.class);
        assertArrayEquals(test.fields, test2.fields);
    }

    @CopyBook(type = FullMapper.class)
    public static class TwoStringArrayToStringArrayDependingOn {
        @CopyBookLine("02 FIELDSCOUNT PIC 9(2).")
        private int xfields1;
        @CopyBookLine("02 FIELDSCOUNT PIC 9(2).")
        private int xfields2;
        @CopyBookLine("02 FIELDS OCCURS 0 TO 10 TIMES PIC X(8) DEPENDING ON FIELDSCOUNT.")
        private String[] fields1;
        @CopyBookLine("02 FIELDS OCCURS 0 TO 10 TIMES PIC X(8) DEPENDING ON FIELDSCOUNT.")
        private String[] fields2;
    }

    @org.junit.Test
    public void twoStringArrayToStringArrayDependingOnTest() throws Exception {
        CopyBookSerializer serializer = new CopyBookSerializer(TwoStringArrayToStringArrayDependingOn.class);
        TwoStringArrayToStringArrayDependingOn test = new TwoStringArrayToStringArrayDependingOn();
        test.fields1 = new String []{ "test", "test2" };
        test.fields2 = new String []{ "tset", "2tset" };
        test.xfields1 = test.fields1.length;
        test.xfields2 = test.fields2.length;
        byte[] testBytes = serializer.serialize(test);
        assertEquals(2 + 2 + 8 * test.fields1.length + 8 * test.fields2.length, testBytes.length);
        TwoStringArrayToStringArrayDependingOn test2 = serializer.deserialize(testBytes, TwoStringArrayToStringArrayDependingOn.class);
        assertArrayEquals(test.fields1, test2.fields1);
        assertArrayEquals(test.fields2, test2.fields2);