How to show proper json response from Scala controller class?

后端 未结 1 1244
予麋鹿
予麋鹿 2021-01-28 05:58

I am trying to get json response from Postgresql database(v9.5) table to display on my view page, I have tried the following, as my application is executing fine, but I am not g

1条回答
  •  有刺的猬
    2021-01-28 06:37

    As indicated in the documentation, Anorm comes with column parsers for the JDBC standart types.

    PostgreSQL JSON type is not one of those. It's a vendor specific type.

    You can deal with this specific conversion in the statement, by casting the SQL column to TEXT before to go through the JDBC (as plain JDBC String so).

    SELECT json_col::TEXT FROM test
    

    You can implement a custom Column[JsValue] (see documentation), that convert the PGObject specific to the PostgreSQL JDBC driver into a Play JsValue.

    You can map the column as anorm.Object (SqlParser.get[anorm.Object]("col")), and deal with the opaque value in your application.

    0 讨论(0)
提交回复
热议问题