arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
437 stars 76 forks source link

Parsing Inner Classes #667

Closed chriszwickerocteris closed 4 years ago

chriszwickerocteris commented 5 years ago

SFM 7.0.0

AsmInstantiatorDefinitionFactory seems to have an issue with inner (non-static) classes when generics are involved: in #visitMethod, parsing desc leads to an additional type as compared to parsing signature, finally leading to an IndexOutOfBoundsException.

Reproducing Test:

public class SfmListTests {
  private static Connection conn;

  @BeforeClass
  public static void init() throws SQLException {
    conn = DriverManager.getConnection("jdbc:postgresql://localhost:4001/testing", "postgres", "testing");
  }

  @Test
  public void failing() throws SQLException {
    final String query = String.join("\n",
      "with t (",
        "id, foo_id",
      " ) as ( values",
        "('a', 'b')",
      ")",
      "select * from t"
    );
    PreparedStatement stmt = conn.prepareStatement(query);
    ResultSet rs = stmt.executeQuery();

    final JdbcMapperFactory mapperFactory = JdbcMapperFactory.newInstance()
      .useAsm(false)
      .ignorePropertyNotFound()
      .addKeys("id")
      .addKeys("foos_id")
    ;
    final Iterator<Root> iterator = mapperFactory.newMapper(Root.class).iterator(rs);
  }

  public class Root {
    private String id;
    private List<Foo> foos;

    public Root() {}
    public Root(final String id, final List<Foo> foos) {
      this.id = id;
      this.foos = foos;
    }
  }

  class Foo {
    private String id;

    public Foo() {}
    public Foo(final String id) {
      this.id = id;
    }
  }
}
arnaudroger commented 5 years ago

will see If can change that, the inner class have issue though because it needs a ref to theouter class, which might not be available ...

chriszwickerocteris commented 5 years ago

Not urgent, just came across this - easy to work around...