Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check value on a Postgres JsonB field? #101

Open
jfisbein opened this issue Sep 29, 2020 · 3 comments
Open

How to check value on a Postgres JsonB field? #101

jfisbein opened this issue Sep 29, 2020 · 3 comments

Comments

@jfisbein
Copy link

jfisbein commented Sep 29, 2020

I trying to check the values inserted on a table where a field is of the type jsonb.

When I run something like this:

assertThat(eventsTable)
      .row(0)
      .value("data").isEqualTo("{\"key\": \"value\"}");

I get the following error:

[Value at index 0 (column name : DATA) of Row at index 0 of events table] 
Expecting:
  <{"key": "value"}>
to be of type
  <[TEXT, NUMBER, DATE, TIME, DATE_TIME, UUID]>
but was of type
  <NOT_IDENTIFIED> (org.postgresql.util.PGobject)

Here is the table content:

[events table]
|-----------|---------|-------------------------------------------------------|
|           |         |                                                       |
|           | PRIMARY | DATA                                                  |
|           | KEY     | (NOT_IDENTIFIED : class org.postgresql.util.PGobject) |
|           |         | Index : 0                                             |
|-----------|---------|-------------------------------------------------------|
| Index : 0 |         | {"key": "value"}                                      |
|-----------|---------|-------------------------------------------------------|

Using assertj-db 2.0.0

Is there any way I can check the content of a PostgreSQL jsonb column?

@VanRoy
Copy link
Member

VanRoy commented Oct 1, 2020

Hi @jfisbein , Indeed it's a good question, do - you tried with Condition assertion ?

I will check that on side and I will send you a feedback soon.

@VanRoy VanRoy self-assigned this Oct 1, 2020
@VanRoy VanRoy added the question label Oct 1, 2020
@VanRoy VanRoy closed this as completed Oct 1, 2020
@VanRoy VanRoy reopened this Oct 1, 2020
@jfisbein
Copy link
Author

jfisbein commented Oct 2, 2020

Thanks @VanRoy I solved it using Condition
new Condition<>(d -> d.getValue().equals("my expected value"), "Json value is");

@VanRoy
Copy link
Member

VanRoy commented Oct 2, 2020

Great @jfisbein , I still try to see if we can improve the JSON support.

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

No branches or pull requests

2 participants