JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.1k stars 677 forks source link

fix: EXPOSED-261 [H2] JSON column throws when setting nullable parameters #1969

Closed bog-walk closed 6 months ago

bog-walk commented 6 months ago

When using H2, attempting to insert null into a nullable JSON column results in an NPE that states:

null cannot be cast to non-null type kotlin.String

When using PostgreSQL-NG, attempting to retrieve a null value stored in a JSON column results in a deserialization error because a non-null object is read with string value 'null'.

Both these issues occur because the JsonColumnType override for setParameter() does not handle null values correctly. In the case of PostgreSQL-NG, this meant that a null value was being stored as a string literal instead of SQL NULL.

If null values are passed, the dialect overrides now ensure that they are sent to the super implementation so they can be handled as SQL NULL.