001package org.javasimon.utils.bean;
002
003/**
004 * Converter from String to Byte.
005 *
006 * @author <a href="mailto:ivan.mushketyk@gmail.com">Ivan Mushketyk</a>
007 */
008public class ToByteConverter implements Converter {
009
010        @Override
011        public Byte convert(Class<?> targetClass, String strVal) throws ConvertException {
012                if (strVal == null) {
013                        return null;
014                }
015
016                try {
017                        return Byte.parseByte(strVal);
018                } catch (NumberFormatException ex) {
019                        throw new ConvertException(
020                                String.format("Cannot convert string '%s' to Byte", strVal));
021                }
022        }
023}