typelevel / typelevel/doobie

Circe throws an exception when parsing nested JSONB field that is null.

Open
#2,123 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
2.2k
Forks
379
Avg merge
14m
Merged PRs (30d)
8

Description

If a query returns a nested structure from a JSON(b) field, the empty field must be absent for the query to work. If the field is present and null, there is a circe exception thrown.

Example query:

sql"SELECT address->'coordinates' FROM profile"

Definition of the Coordinates and Address types:

case class Coordinates(latitude: Double, longitude: Double)
case class Address(coordinates: Option[Coordinates])

Definition of the custom mapping:

given Meta[Coordinates] = new Meta(pgDecoderGet, pgEncoderPut)
given Meta[Address] = new Meta(pgDecoderGet, pgEncoderPut)

The query works for the following contents of the address column:
NULL
{}

The query throws and exception for the following contents of the address column:
{"coordinates":null}
The exception message is: io.circe.DecodingFailure$DecodingFailureImpl: DecodingFailure at : Got value 'null' with wrong type, expecting object

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the query with the shown Coordinates, Address, and custom Meta definitions, comparing NULL, {}, and {"coordinates":null} values. Trace the decoding path that handles the nested JSONB field; done means a present null coordinates value no longer raises the reported Circe DecodingFailure.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, scala
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.