vertx-jdbc-client icon indicating copy to clipboard operation
vertx-jdbc-client copied to clipboard

getJsonArray() throws ClassCastException from v4.2.0 upwards

Open komape opened this issue 1 year ago • 2 comments

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.

komape avatar Sep 01 '22 09:09 komape

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 ?

zero88 avatar Oct 26 '22 03:10 zero88

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).

vietj avatar Nov 14 '22 08:11 vietj