question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON not serialized in prepared reactive query

See original GitHub issue

Hi,

I am not sure if this is a bug report or a question.

For reasons we are currently trying to use a psql table with a single JSON column and some constraints on the id field of the data:

CREATE TABLE contracts (
    json JSONB NOT NULL,
    CONSTRAINT validate_id CHECK( json ? 'id' )
);

CREATE UNIQUE INDEX contracts_ids_idx ON contracts( (json ->> 'id') );

Our relevant Java code (including code for a non-prepared version) in the respective write routine looks like this:

import io.reactiverse.reactivex.pgclient.PgPool;
import io.reactiverse.reactivex.pgclient.data.Json;
import io.vertx.core.json.JsonObject;

public class ContractRepository {

    private final PgPool pool; //instantiated outside the posted code

    private static final String CREATE_QUERY = "INSERT INTO contracts (json) VALUES ($1);";
    private static final String CREATE_QUERY_NOT_PREPARED = "INSERT INTO contracts (json) VALUES ('%s');";

    public Single<UUID> rxStoreNewContract(Contract contract) {

        UUID uuid = contract.getId();

        return Single.just(contract)
              .map(JsonObject::mapFrom)
              .map(Json::create)
              .flatMap( foo -> pool.rxPreparedQuery(CREATE_QUERY, Tuple.of(foo)) )
              //.flatMap(foo -> pool.rxQuery(String.format(CREATE_QUERY_NOT_PREPARED, foo)))
              .map(ar -> uuid);
    }
}

The non-prepared commented version works fine. And if I run this code and inspect foo in the debugger, it looks fine too (see attached screenshot). contract_in_reactivePg

But the db complains about a null value in the json column:

06:42:59.688 [vert.x-eventloop-thread-0] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: null value in column "json" violates not-null constraint
io.reactiverse.pgclient.PgException: null value in column "json" violates not-null constraint
	at io.reactiverse.pgclient.impl.QueryCommandBase.handleErrorResponse(QueryCommandBase.java:65)
	at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.decodeError(MessageDecoder.java:253)
	at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.decodeMessage(MessageDecoder.java:142)
	at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.channelRead(MessageDecoder.java:122)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)

I tried to trace the code in the debugger but pretty soon got lost. So I can’t say if this is a bug or whether we are “holding it wrong”.

We are running this in Micronaut and Micronauts preconfigured reactive-pg-client version is 0.10.5 . Updating to 0.10.9 didn’t help and updating to 0.11.2 left us with some runtime exceptions that are probably solvable but we didn’t pursue.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vietjcommented, May 9, 2019

thanks @agschaid

0reactions
vietjcommented, Jun 10, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON not serialized in prepared reactive query #270 - GitHub
Hi, I am not sure if this is a bug report or a question. For reasons we are currently trying to use a...
Read more >
Cannot I use the outcome of a json serialize in a aggregate
Hi Roelof, You should not serialize the structure to json. You can access the properties from the stucture directly in your aggregate filter....
Read more >
Writing JSON REST Services - Quarkus
This is an introduction to writing JSON REST services with Quarkus. A more detailed guide about RESTEasy Reactive is available here.
Read more >
c# - Deserializing object that inherits from ReactiveObject from ...
I am trying to deserialize some json into some simple objects that inherit from Reactive UI's ReactiveObject class.
Read more >
Custom Reactive JSON parsing
There are a bunch of various libraries to parse JSON: good old Gson, Jackson, or more modern Moshi, kotlinx-serialization and there are more ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found