Skip to content

Errors_CSFM_GETTER_NOT_FOUND

Arnaud Roger edited this page Aug 15, 2018 · 12 revisions

Why ?

When mapping from a source - ie. ResultSet - to an object sfm could not find a getter that would return the type of the property.

Are you trying to map to an element of List?

class Foo {
   List<String> bars;
}

failed on column "bars" with an error message like

Could not find getter for ColumnKey [columnName=bars, columnIndex=1, sqlType=-99999] type ParameterizedTypeImpl{rawType=interface java.util.List, types=[class java.lang.String]} path bars

you will need to rename the column either in the query or by adding an alias to force sfm to map the column to the underlying element. the column name needs to be bars_val, it does not have to be val can be anything of your liking.

select bars as bars_val

Then what?

You will need to provide a custom getter to the framework that will build the specific type from the source object. you can also provide a getter factory that will build a getter based on the field key.

example

    JdbcMapperFactory
           .newInstance()
           .addColumnProperty("bar", 
               new GetterProperty(new Getter<ResultSet, Bar2>() {
                   @Override
                   public Bar2 get(ResultSet target) throws Exception {
                       return new Bar2(target.getString("bar"), 2);
                   }
               }))
           .newBuilder(Foo2.class)
           .addKey("bar").mapper();
  
    CsvMapperFactory
            .newInstance()
            .addColumnProperty("bar", 
                new CustomReaderProperty(new CellValueReader<Bar2>() {
                    @Override
                    public Bar2 read(char[] chars, int offset, int length, 
                                     ParsingContext parsingContext) {
                        return new Bar2(
                            StringCellValueReader
                                .readString(chars, offset, length), 2);
                    }
                }))
            .newBuilder(Foo2.class)
            .addMapping("bar").mapper();

More details

PS : what is CSFM - Constant Source Field Mapper, ie ResultSet to T

Clone this wiki locally