Skip to content

A new interface and implementation for FieldSet [BATCH-1560] #2025

Open
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions