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

column[Option[JsValue]] read null when Option is None #297

Closed
WayneWang12 opened this issue Aug 18, 2016 · 8 comments
Closed

column[Option[JsValue]] read null when Option is None #297

WayneWang12 opened this issue Aug 18, 2016 · 8 comments

Comments

@WayneWang12
Copy link

I have figured out that this problem is due to

 trait PlayJsonImplicits {
    implicit val playJsonTypeMapper: JdbcType[JsValue] =
      new GenericJdbcType[JsValue](
        pgjson,
        (v) => Json.parse(v),
        (v) => Json.stringify(v),
        zero = JsNull,
        hasLiteralForm = false
      )

    implicit def playJsonColumnExtensionMethods(c: Rep[JsValue]) = {
      new JsonColumnExtensionMethods[JsValue, JsValue](c)
    }
    implicit def playJsonOptionColumnExtensionMethods(c: Rep[Option[JsValue]]) = {
      new JsonColumnExtensionMethods[JsValue, Option[JsValue]](c)
    }
  }

And I've changed the zero = JsNull to zero = null then my old code work. It is because when get across null value from database, slick-pg will consider it as JsNull, which is not a null value, so Option will have Some(JsNull). After that, JsNull in Some is transferred to null, so we've got Some(null) problem, which is really inconvenient for us to handle. Hope this could be fix. Thx.

@tminglei
Copy link
Owner

Well, the null default mechanism was already discarded by slick. So we'd better remove it too.

@tminglei
Copy link
Owner

Removed null default in 7d4b0dd.

@WayneWang12
Copy link
Author

Thanks!

@caeus
Copy link

caeus commented Sep 2, 2016

Suffering this... Is there a version where this' been already fixed?

@tminglei
Copy link
Owner

tminglei commented Sep 3, 2016

@caeus the removing change was released in slick-pg v0.15.0-M2, you can try it.

@tminglei tminglei closed this as completed Sep 3, 2016
@haya14busa
Copy link

Hi there @tminglei,

Do you have any plan to backport the patch to 0.14.x?

v0.15.0-M3 is pre-release and it requires updating slick version to v3.2.0-M2 as well.

@tminglei
Copy link
Owner

Hi @haya14busa, no plan to backport to slick-pg 0.14.x, since zero value is an built-in mechanism before slick v3.2.0, and slick-pg followed that for a long time.

@haya14busa
Copy link

Thank you for the reply.

Hmm... ok I understood. I'll deal with the problem by defining wrapper trait of PlayJsonImplicits to make zero = JsNull to zero = null

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

No branches or pull requests

4 participants