1

I have datatype called "json" in postgres db. I wanted to insert data gson object from java code.

How can i insert gson object data into json column of table in postgres database?

Can any one help me?

Thanks,

alfonx
  • 6,936
  • 2
  • 49
  • 58
user3701757
  • 41
  • 1
  • 3

1 Answers1

4

In Postgres SQL the json type is similar to text type and in java the corresponding mapping will be String type.The important thing is that json String must be valid json because there is a validation at database end.

Refer this link for clarification

Ashok_Pradhan
  • 1,159
  • 11
  • 13
  • 1
    Unfortunately, PostgreSQL is painfully strict about typecasts, and will complain about a json vs text type mismatch. You'll need to `CREATE CAST` to make it work properly. See http://stackoverflow.com/questions/15974474/mapping-postgresql-json-column-to-hibernate-value-type/15983429#15983429 – Craig Ringer Jun 16 '14 at 11:51