Hi mauro,
Did that not work for you? I tried the same thing and it seemed to
work for me.
First I created a LongTypeHandler:
public class LongTypeHandler implements TypeHandler {
@Override
public Long parse(String text) throws TypeConversionException {
if (text == null || "".equals(text.trim()))
return null;
try {
return Long.parseLong(text);
}
catch (NumberFormatException ex) {
throw new TypeConversionException("Invalid long", ex);
}
}
@Override
public String format(Object value) {
if (value == null)
return "";
else
return ((Long)value).toString();
}
@Override
public Class<?> getType() {
return Long.class;
}
}
Then using the following mapping file where I overwrite the default
Long type handler with my own:
<beanio xmlns="
http://www.beanio.org/2011/01">
<stream name="stream" format="fixedlength">
<typeHandler type="Long" class="test.LongTypeHandler" />
<record name="record" class="map">
<field name="value1" type="Long" length="10" padding="0"
justify="right"/>
<field name="value2" type="Long" length="10" padding="0"
justify="right"/>
</record>
</stream>
</beanio>
I was able to parse the following file (courier font would be nice
here):
00000000000000000000
0000000099
00000000010000000001
And got the following results for each record:
{value1=0, value2=0}
{value1=null, value2=99}
{value1=null, value2=null}
{value1=1, value2=1}
Is this what you are trying to do?
Thanks,
Kevin