Skip to content

Instantly share code, notes, and snippets.

@chaoky
Created September 7, 2021 19:27
Show Gist options
  • Save chaoky/253c8edda0c66b2c1731f607f94ba9ac to your computer and use it in GitHub Desktop.
Save chaoky/253c8edda0c66b2c1731f607f94ba9ac to your computer and use it in GitHub Desktop.
Decode empty strings to None in scala circe
given emptyStringToNull[A](using d: Decoder[A]): Decoder[Option[A]] =
Decoder.decodeOption.prepare(cursor =>
cursor.withFocus(json => if json.toString == "\"\"" then Json.Null else json)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment