Обсуждение: best way to convert JSONB object from result

Поиск
Список
Период
Сортировка

best way to convert JSONB object from result

От
Tom Smith
Дата:
Hi:

I am trying to convert to a Java or Map object
from resultset with a jsonb column.
Currently, I am using

String jsonString = resultSet.getString("jsonb_column_name")

then I convert from jsonString to a Map<String,Object>  or a Java class object.

This is obviously inefficient.  What would be most efficient (not too complicated)

Thanks in Advance

Re: best way to convert JSONB object from result

От
Dave Cramer
Дата:
Use boon,jackson or some other json parser to parse it into an object. 

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 19 August 2015 at 15:20, Tom Smith <tomsmith1989sk@gmail.com> wrote:
Hi:

I am trying to convert to a Java or Map object
from resultset with a jsonb column.
Currently, I am using

String jsonString = resultSet.getString("jsonb_column_name")

then I convert from jsonString to a Map<String,Object>  or a Java class object.

This is obviously inefficient.  What would be most efficient (not too complicated)

Thanks in Advance

Re: best way to convert JSONB object from result

От
Mikko Tiihonen
Дата:

You are using the most efficient way. I tried to look into converting the jsonb value directly to some json parser in the jdbc driver, but it turned out the the server always sends jsonb as a serialized string instead of the faster-to-parse internal jsonb storage format.


-Mikko


From: pgsql-jdbc-owner@postgresql.org <pgsql-jdbc-owner@postgresql.org> on behalf of Tom Smith <tomsmith1989sk@gmail.com>
Sent: 19 August 2015 22:20
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] best way to convert JSONB object from result
 
Hi:

I am trying to convert to a Java or Map object
from resultset with a jsonb column.
Currently, I am using

String jsonString = resultSet.getString("jsonb_column_name")

then I convert from jsonString to a Map<String,Object>  or a Java class object.

This is obviously inefficient.  What would be most efficient (not too complicated)

Thanks in Advance