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

failure extracting null to None when strict and disallow-nulls are specified #1398

Open
yoganandc opened this issue Dec 9, 2023 · 0 comments

Comments

@yoganandc
Copy link

json4s version

4.0.6

scala version

2.13.5

jdk version

openjdk version "1.8.0_282"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.282-b08, mixed mode)

I have a definition

case class Test(t: Option[String])

The json

{"t": null}

is extracted successfully below

implicit val formats: Formats = DefaultFormats.strict
read[Test](j)

// val res8: Test = Test(None)

and here too

implicit val formats: Formats = DefaultFormats.withExtractionNullStrategy(ExtractionNullStrategy.Disallow)
read[Test](j)

// val res9: Test = Test(None)

but not when i combine both

implicit val formats: Formats = 
  DefaultFormats.withExtractionNullStrategy(ExtractionNullStrategy.Disallow).strict
read[Test](j)

// org.json4s.MappingException: No usable value for t
// Did not find value which can be converted into java.lang.String
//   at org.json4s.reflect.package$.fail(package.scala:56)

I would like to have both. Am I misunderstanding the intentions behind these flags or is this a bug?

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

No branches or pull requests

1 participant