Skip to content

feat: map JSON and JSONB columns to String - #51

Merged
omer-cengel merged 3 commits into
masterfrom
feature/json-and-jsonb-text-types
Sep 28, 2026
Merged

omer-cengel merged 3 commits into
masterfrom
feature/json-and-jsonb-text-types

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

PostgreSQL JSON and JSONB columns now map to String holding the JSON text, for both query parameters and result components. PostgreSQL rejects text bound as varchar for these types, and the driver does not support reading them through getObject(position, String.class). So generated code passes JSON arguments through a new runtime value that is bound without a declared SQL type, and reads JSON columns with getString.

Changes

  • Schema parsing maps JSON and JSONB, in any case, in CREATE TABLE, ALTER TABLE ... ADD COLUMN, and ALTER COLUMN ... TYPE. Both resolve to String, and nullability is parsed as for any other column.
  • The runtime adds dev.sqlcj.runtime.UntypedText, a record carrying any text. JdbcQueryExecutor binds it with setObject(position, value, Types.OTHER), so PostgreSQL types the text, or a null, from the context of its placeholder. Every other argument is bound exactly as before.
  • Generated repositories pass each JSON or JSONB argument as new dev.sqlcj.runtime.UntypedText(value) at every binding position of its placeholder, and read JSON and JSONB columns with resultSet.getString(position). Generated imports are unchanged, and output for all other types is byte-for-byte the same.
  • JSON reads back exactly as written. JSONB reads back as PostgreSQL renders it, and = on a JSONB column matches by value.
  • Tests cover the schema spellings, the runtime binding, the generated source and its compilation, and a PostgreSQL round trip of null and non-null values plus a JSONB equality lookup.
  • The PostgreSQL type and query documentation describes the mapping, the reads, the binding, and null handling.

Scope and non-goals

  • json[] and jsonb[] columns stay recorded as unsupported types.
  • sqlcj does not parse, validate, or normalize the JSON text and adds no JSON library dependency.
  • JSON operators, type overrides, and mapping JSON to structured Java types are not included.
  • Neither generated code nor the runtime depends on the PostgreSQL JDBC driver.

Generated code passes JSON and JSONB arguments as UntypedText so
PostgreSQL types the text from its context, and reads those columns
with getString. The text is never parsed or normalized.
@omer-cengel
omer-cengel merged commit dbd1d49 into master Sep 28, 2026
6 checks passed
@omer-cengel
omer-cengel deleted the feature/json-and-jsonb-text-types branch September 28, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant