
org.sfm.csv.impl.writer.JodaTimeFormattingAppender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm Show documentation
Show all versions of sfm Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.sfm.csv.impl.writer;
import org.joda.time.ReadableInstant;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.sfm.csv.CellWriter;
import org.sfm.map.FieldMapper;
import org.sfm.map.MappingContext;
import org.sfm.reflect.Getter;
public class JodaTimeFormattingAppender implements FieldMapper {
private final CellWriter cellWriter;
private final DateTimeFormatter formatter;
private final Getter getter;
@SuppressWarnings("unchecked")
public JodaTimeFormattingAppender(Getter getter, DateTimeFormatter formatter, CellWriter cellWriter) {
this.getter = (Getter)getter;
this.formatter = formatter;
this.cellWriter = cellWriter;
}
@SuppressWarnings("unchecked")
public JodaTimeFormattingAppender(Getter getter, String pattern, CellWriter cellWriter) {
this.getter = (Getter)getter;
this.formatter = DateTimeFormat.forPattern(pattern);
this.cellWriter = cellWriter;
}
@Override
public void mapTo(T source, Appendable target, MappingContext super T> context) throws Exception {
cellWriter.writeValue(formatter.print(getter.get(source)), target);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy