New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement JSON and JSONB codecs #161
Conversation
Thanks for your PR. As stated in #39, supporting JSON(Oid) is something that we want. What we do not want is including a dependency to any JSON library in the core driver. We should expose JSON payload as binary (byte array, ByteBuffer, ByteBuf?, InputStream) data type, similar for writing. Any JSON processors should live on the client library or application level or can be contributed by driver extensions (driver extensibility is on our roadmap). We鈥檙e happy to merge basic support for now, without Jackson. |
@mp911de that makes sense! I updated the branch with the suggested approach, please let me know what you think 馃檪 PS: I included both JSON and JSONB codecs |
No worries, the branch name isn鈥檛 an issue at all. Codecs already look well. Recently we kept binary and text formats within a single codec (see https://github.com/r2dbc/r2dbc-postgresql/blob/master/src/main/java/io/r2dbc/postgresql/codec/AbstractNumericCodec.java). I鈥檇 suggest adding an AbstractJsonCodec with concrete subtypes for ByteBuffer, ByteBuf, byte[] and InputStream. The need for multiple subtypes is current a flaw of our approach that we will need to cleanup. |
@mp911de awesome, good to know we're going the right way! Just to be clear, we'll need the following codecs based on an
I'm not sure we can have |
Partially. Codec decoding is based on format, type oid and the requested We want to introduce with R2DBC 0.9 type descriptors so a value can be encoded using a more specific codec. |
Thanks for your PR. I'm going to take it from here. |
There's one fundamental issue that became obvious during integration testing requiring us to rethink the API. Using
as Postgres isn't able to convert between json/jsonb and bytea or varchar. It seems that we should add a dedicated |
Introduce Json wrapper type to avoid conflicts with BYTEA (byte[], ByteBuffer) encoding. Split JSON codec into AbstractJsonCodec and subclasses for proper wrapper and scalar type handling. Json wrapper allows exchange of JSON payload without buffer copies. Add license headers. Extend integration tests. [#161]
That's merged and polished now. |
@mp911de I was actually looking into that. A dedicated Thanks a lot for taking the time to check and work on the PR. I'm glad this was of help and it got merged. Cheers! |
Hi @mp911de! I'm opening this PR as an alternative to #39 but using Jackson dependency instead of GSON. I also took into account your suggestions to provide a certain level of flexibility and added return types for
ByteBuf
,byte[]
,String
andInputStream
.I only added the codec to
JSONB
since we'll need another codec forJSON
. This is because thedoEncode(Object value)
method does not have any way to choose which one it should encode: JSON or JSONB.I can open another PR after this one with the
JSON
codec or add it to this PR if you think it would be ok 馃檪Cheers!