// Path: copybook4java/src/main/java/com/nordea/oss/copybook/converters/TypeConverter.java
// public interface TypeConverter {
//     void initialize(TypeConverterConfig config);
//     void validate(Class<?> type, int size, int decimals);
//     TypeConverter copy(Class<?> type) throws IllegalAccessException, InstantiationException;
//     Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding);
//     byte[] from(Object value, int length, int decimals, boolean addPadding);
// }
// 
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/exceptions/CopyBookException.java
// public class CopyBookException extends RuntimeException {
//     private static final long serialVersionUID = 28118369047109260L;
//     public CopyBookException(String message) {
//         super(message);
//     }
// 
//     public CopyBookException(String message, TypeConverterException ex) {
//         super(message + ": " + ex.getClass().getSimpleName() + " :" + ex.getMessage());
//     }
// 
//     public CopyBookException(String message, Exception ex) {
//         super(message + ": " + ex.getClass().getSimpleName() + " :" + ex.getMessage());
//     }
// }


import com.nordea.oss.copybook.converters.TypeConverter;
import com.nordea.oss.copybook.exceptions.CopyBookException;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
        this.counterKey = counterKey;
        this.converter = converter;
        this.name = name;
        this.size = size;
        this.decimals = decimals;
        this.minOccurs = minOccurs;
        this.maxOccurs = maxOccurs;
    }

    public Object setBytes(Object obj, ByteBuffer buffer, boolean removePadding) {
        byte[] bytes = new byte[this.size];
        buffer.get(bytes);
        return setBytes(obj, bytes, 0,  bytes.length, removePadding);
    }

    public Object setBytes(Object obj, byte[] bytes, boolean removePadding) {
        return setBytes(obj, bytes, 0, bytes != null ? bytes.length : 0, removePadding);
    }

    public Object setBytes(Object obj, byte[] bytes, int offset, int length, boolean removePadding) {
        try {
            Object value = bytes != null ? converter.to(bytes, offset, length, this.decimals, removePadding) : null;
            field.set(obj, value);
            return value;

        } catch (IllegalAccessException ex) {
            // We already set it to accessible so this should not happen
            return null;

        } catch (Exception ex) {
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/converters/TypeConverter.java
// public interface TypeConverter {
//     void initialize(TypeConverterConfig config);
//     void validate(Class<?> type, int size, int decimals);
//     TypeConverter copy(Class<?> type) throws IllegalAccessException, InstantiationException;
//     Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding);
//     byte[] from(Object value, int length, int decimals, boolean addPadding);
// }
// 
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/exceptions/CopyBookException.java
// public class CopyBookException extends RuntimeException {
//     private static final long serialVersionUID = 28118369047109260L;
//     public CopyBookException(String message) {
//         super(message);
//     }
// 
//     public CopyBookException(String message, TypeConverterException ex) {
//         super(message + ": " + ex.getClass().getSimpleName() + " :" + ex.getMessage());
//     }
// 
//     public CopyBookException(String message, Exception ex) {
//         super(message + ": " + ex.getClass().getSimpleName() + " :" + ex.getMessage());
//     }
// }


// Path: copybook4java/src/main/java/com/nordea/oss/copybook/serializers/CopyBookField.java
import com.nordea.oss.copybook.converters.TypeConverter;
import com.nordea.oss.copybook.exceptions.CopyBookException;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

        this.counterKey = counterKey;
        this.converter = converter;
        this.name = name;
        this.size = size;
        this.decimals = decimals;
        this.minOccurs = minOccurs;
        this.maxOccurs = maxOccurs;
    }

    public Object setBytes(Object obj, ByteBuffer buffer, boolean removePadding) {
        byte[] bytes = new byte[this.size];
        buffer.get(bytes);
        return setBytes(obj, bytes, 0,  bytes.length, removePadding);
    }

    public Object setBytes(Object obj, byte[] bytes, boolean removePadding) {
        return setBytes(obj, bytes, 0, bytes != null ? bytes.length : 0, removePadding);
    }

    public Object setBytes(Object obj, byte[] bytes, int offset, int length, boolean removePadding) {
        try {
            Object value = bytes != null ? converter.to(bytes, offset, length, this.decimals, removePadding) : null;
            field.set(obj, value);
            return value;

        } catch (IllegalAccessException ex) {
            // We already set it to accessible so this should not happen
            return null;

        } catch (Exception ex) {
            throw new CopyBookException(getFieldName() + ": ", ex);