vert-x3 / vertx-jdbc-client

JDBC support for Vert.x
Apache License 2.0
126 stars 90 forks source link

getJsonArray() throws ClassCastException from v4.2.0 upwards #290

Open komape opened 2 years ago

komape commented 2 years ago

Version

v4.2.0

Context

We have a PostgreSQL database with a column of type Array. The following line of code always returned an JsonArray without any problems. Once we migrated to version 4.2.x this started to throw a ClassCastException because it returns an Object. There were no changes to the database. Our guess is that the JDBCDecoder from #235 somehow fails to parse the content of the cell into an array and instead just returns an Object.

int pos = 3; // the column with the array type
// row is an JsonArray
final JsonArray jsonArray = row.getJsonArray(pos);

The documentation does'nt mention any breaking changes regarding this.

Do you have a reproducer?

No.

Steps to reproduce

  1. Have a database with a column of type ARRAY and a row containing valid data.
  2. Request the data and read from it.
zero88 commented 2 years ago

Actually, java.sql.Array will be converted to Object[], and keeps this value in Row/Tuple.

My preference is Object[] to compatible with another lib/tool. And, in Tuple should introduce the JsonArray converter.

https://github.com/eclipse-vertx/vertx-sql-client/blob/75ee2e4ad73d0fcf736efd80f5ea4569b72f898a/vertx-sql-client/src/main/java/io/vertx/sqlclient/Tuple.java#L414-L432

How do you think @vietj ?

vietj commented 2 years ago

we should avoid using primitive arrays with Tuple instead of trying to use a different type than what the Tuple expects (or the default methods of Tuple should be reimplemented then).