Skip to content

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

Open
@slavaschmidt

Description

@slavaschmidt

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions