Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Customize upickle to support both null and empty bracket [] as None #568

Closed
kaitks opened this issue Apr 11, 2024 · 0 comments
Closed

Customize upickle to support both null and empty bracket [] as None #568

kaitks opened this issue Apr 11, 2024 · 0 comments

Comments

@kaitks
Copy link

kaitks commented Apr 11, 2024

Convert [] as None is the default behavior of upickle, and per document I managed to convert null to None by using an customized upickle

object OptionPickler extends upickle.AttributeTagged {
  override implicit def OptionWriter[T: Writer]: Writer[Option[T]] =
    implicitly[Writer[T]].comap[Option[T]] {
      case None => null.asInstanceOf[T]
      case Some(x) => x
    }

  override implicit def OptionReader[T: Reader]: Reader[Option[T]] = {
    new Reader.Delegate[Any, Option[T]](implicitly[Reader[T]].map(Some(_))){
      override def visitNull(index: Int) = None
    }
  }
}

How to make a custom upickle that can convert both null and [] to None?

@com-lihaoyi com-lihaoyi locked and limited conversation to collaborators Jul 11, 2024
@lihaoyi lihaoyi converted this issue into discussion #600 Jul 11, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant