Skip to content

Instantly share code, notes, and snippets.

@krams915
Created February 13, 2012 08:45
Show Gist options
  • Save krams915/1815109 to your computer and use it in GitHub Desktop.
Save krams915/1815109 to your computer and use it in GitHub Desktop.
package org.krams.batch;
import org.krams.domain.User;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
public class MultiUserFieldSetMapper implements FieldSetMapper<User> {
@Override
public User mapFieldSet(FieldSet fs) {
if(fs == null){
return null;
}
User user = new User();
user.setUsername(removePrefix(fs.readString("username")));
user.setPassword(fs.readString("password"));
user.setLastName(fs.readString("lastName"));
user.setFirstName(fs.readString("firstName"));
return user;
}
private String removePrefix(String token) {
String[] tokens = token.split(";");
if (tokens.length == 2) {
return tokens[1];
}
return token;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment