// 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/main/java/com/nordea/oss/copybook/converters/StringToString.java
// public class StringToString extends TypeConverterBase {
//     @Override
//     public void validate(Class<?> type, int size, int decimals) {
//         if(!(String.class.equals(type))) {
//             throw new TypeConverterException("Only supports converting to and from String");
//         }
//     }
// 
//     @Override
//     public Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding) {
//         if(ByteUtils.allEquals(bytes, this.nullFillerByte, offset, bytes.length)) { // All of value is null filler
//             if(this.defaultValue != null) {
//                 return this.defaultValue;
// 
//             } else {
//                 return null;
//             }
// 
//         } else {
//             return getString(bytes, offset, length, removePadding, 0);
//         }
//     }
// 
//     @Override
//     public byte[] from(Object value, int length, int decimals, boolean addPadding) {
//         byte[] strBytes = null;
//         if(value != null || this.defaultValue != null) {
//             strBytes = (value != null ? (String)value : this.defaultValue).getBytes(this.charset);
//             if (strBytes.length > length) {
//                 throw new TypeConverterException("Field to small for value: " + length + " < " + strBytes.length);
//             }
//             if (addPadding) {
//                 strBytes = padBytes(strBytes, length);
//             }
// 
//         } else if(addPadding) {
//             strBytes = new byte[length];
//             Arrays.fill(strBytes, this.nullFillerByte);
//         }
// 
//         return strBytes;
//     }
// }
// 
// 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.CopyBookSerializer;
import com.nordea.oss.copybook.annotations.CopyBook;
import com.nordea.oss.copybook.annotations.CopyBookFieldFormat;
import com.nordea.oss.copybook.annotations.CopyBookLine;
import com.nordea.oss.copybook.converters.StringToString;
import com.nordea.oss.copybook.exceptions.CopyBookException;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import java.math.BigInteger;
import static org.junit.Assert.*;
/*
 * Copyright (c) 2015. Troels Liebe Bentsen <tlb@nversion.dk>
 * Copyright (c) 2016. Nordea Bank AB
 * Licensed under the MIT license (LICENSE.txt)
 */

package com.nordea.oss.copybook.serializers;




public class CopyBookMapperNullValuesTest {

    @Rule
    public ExpectedException expectedEx = ExpectedException.none();

    @CopyBook(type = FullMapper.class)
// 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/main/java/com/nordea/oss/copybook/converters/StringToString.java
// public class StringToString extends TypeConverterBase {
//     @Override
//     public void validate(Class<?> type, int size, int decimals) {
//         if(!(String.class.equals(type))) {
//             throw new TypeConverterException("Only supports converting to and from String");
//         }
//     }
// 
//     @Override
//     public Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding) {
//         if(ByteUtils.allEquals(bytes, this.nullFillerByte, offset, bytes.length)) { // All of value is null filler
//             if(this.defaultValue != null) {
//                 return this.defaultValue;
// 
//             } else {
//                 return null;
//             }
// 
//         } else {
//             return getString(bytes, offset, length, removePadding, 0);
//         }
//     }
// 
//     @Override
//     public byte[] from(Object value, int length, int decimals, boolean addPadding) {
//         byte[] strBytes = null;
//         if(value != null || this.defaultValue != null) {
//             strBytes = (value != null ? (String)value : this.defaultValue).getBytes(this.charset);
//             if (strBytes.length > length) {
//                 throw new TypeConverterException("Field to small for value: " + length + " < " + strBytes.length);
//             }
//             if (addPadding) {
//                 strBytes = padBytes(strBytes, length);
//             }
// 
//         } else if(addPadding) {
//             strBytes = new byte[length];
//             Arrays.fill(strBytes, this.nullFillerByte);
//         }
// 
//         return strBytes;
//     }
// }
// 
// 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/test/java/com/nordea/oss/copybook/serializers/CopyBookMapperNullValuesTest.java
import com.nordea.oss.copybook.CopyBookSerializer;
import com.nordea.oss.copybook.annotations.CopyBook;
import com.nordea.oss.copybook.annotations.CopyBookFieldFormat;
import com.nordea.oss.copybook.annotations.CopyBookLine;
import com.nordea.oss.copybook.converters.StringToString;
import com.nordea.oss.copybook.exceptions.CopyBookException;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import java.math.BigInteger;
import static org.junit.Assert.*;

/*
 * Copyright (c) 2015. Troels Liebe Bentsen <tlb@nversion.dk>
 * Copyright (c) 2016. Nordea Bank AB
 * Licensed under the MIT license (LICENSE.txt)
 */

package com.nordea.oss.copybook.serializers;




public class CopyBookMapperNullValuesTest {

    @Rule
    public ExpectedException expectedEx = ExpectedException.none();

    @CopyBook(type = FullMapper.class)
    @CopyBookFieldFormat(type = StringToString.class, paddingChar = ' ', nullFillerChar = (byte)0, signingType = CopyBookFieldSigningType.PREFIX, rightPadding = false)