Description
Hussachai opened BATCH-1560 and commented
An existing design of org.springframework.batch.item.file.transform.FieldSet is not comfortable to program with (at least for me)
The first disadavantage.
Because it uses primitive type. Converting value to primitive type may lead to NPE easily. I know this issue may be solved with defaultValue.
But if I'd like to check null there are two ways to do this 1) define some defaultValue that represent as null 2) check the exception. I think
many people don't think it's good idea to do that. They may recommend to check null || empty on readString() before further processing.
For example.
cust.salary = fs.readInt("salary"); // if salary has no value NPE will be raised.
To solve above problem
cust.salary = fs.readInt("salary",-1); //application must know -1 mean null
if(StringUtils.isNotEmpty(fs.readString())){
cust.salary = fs.readInt("salary");
}
The second is more sense but it has more code to write too.
The proposed method is
cust.salary = fs.read(Integer.class, "salary", null); // I think this is the best way.
The second disadvantage
is the limit of conversion interface it just provides primitive type, date and number
conversion. If I want more such as I want Email object, Money object, Class object, URL object how to do that?
The current interface I must get the string and do the conversion manually.
See the attachment.
I don't know my idea is good enough or not. I just want to share the idea.
For me now I will use this to be the wrapper for the DefaultFieldSet object.
Affects: 2.1.0
Attachments:
- transform.zip (1.46 kB)