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


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