Comments (14)
This seems to be broken again in 2.7.4 and 2.7.5.
I setup my ObjectMapper using
val mapper = new ObjectMapper with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
mapper.registerModule(new JavaTimeModule)
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false)
and the following test fails
val json = mapper.writeValueAsString(C(None, None))
assert(json === "{}")
[info] - should not serialize null fields *** FAILED ***
[info] "{["a":null,"b":null]}" did not equal "{[]}" (JacksonUtilTest.scala:27)
from jackson-module-scala.
Thanks for the bug report, I'll take a look at why the works for normal classes and see what needs to be added to the case class logic.
from jackson-module-scala.
While I haven't yet worked out a way to support this using JsonInclude.Include.NON_NULL
(which makes the most logical sense, but doesn't appear to have a hook in JsonSerializer
, I have added support in OptionSerializer to recognize and honor JsonInclude.Include.NON_EMPTY
to achieve the same goal.
from jackson-module-scala.
Reopening, as I realize now that this issue is slightly different than #9.
from jackson-module-scala.
I added what I think is a functionally equivalent pair of tests to CaseClassSerializerTest
and was not able to reproduce the problem. If you can, please retest your use case with the latest code and reopen if you continue to have issues.
from jackson-module-scala.
Well it looks like my tests were bad. Reopening as I've fixed the tests and the problem still exists.
from jackson-module-scala.
Ok, filing in some more information so I don't forget it.
- The non-case class isn't succeeding because it's working properly, it's succeeding because the Scala module doesn't currently recognized the property. If I add
@JsonProperty
annotation toTestObject3
, the test fails. - Getting
NOT_NULL
recognized requires that Jackson recognize that it's possible for a non-null value in the JVM to be serialized as JSON "null". Jackson doesn't currently have a hook for this, but I've got an idea for an approach that might work by replacing BeanPropertyWriter with a new version that recognizes "null-like" values.
I should have a fix for this shortly.
from jackson-module-scala.
With jackson 2.1.0 and jackson-module-scala 2.1.1-SNAPSHOT:
case class Foo(val a: String, val b: Option[Int] = None)
@RunWith(classOf[BlockJUnit4ClassRunner])
class TryJSON {
@test
def testNulls() {
val m = new ObjectMapper()
m.registerModule(new DefaultScalaModule())
m.setSerializationInclusion(JsonInclude.Include.NON_NULL)
println(m.writeValueAsString(new Foo(null, None)))
}
}
Prints:
{"a":null,"b":null}
Am I missing something?
from jackson-module-scala.
Nope, my tests are bad, #45 also reported this. Will fix ASAP and issue a 2.1.1 for it.
from jackson-module-scala.
This issue should be resolved in 2.1.1, just released.
from jackson-module-scala.
Yes, works for me correctly now. Thanks for the quick turnaround!
from jackson-module-scala.
Seems still broken in 2.8.3 as well
from jackson-module-scala.
is there a workaround for this ?
from jackson-module-scala.
Use JsonInclude.Include.NON_ABSENT
. See issue 280
from jackson-module-scala.
Related Issues (20)
- Release 2.15.1 HOT 1
- support deserializing Scala Iterators HOT 1
- Release 2.15.2 HOT 2
- Dependency on .class and .tasty files causes footprint bloat for GraalVM NativeImage HOT 5
- Failure to deserialise scala Map when default typing is activated HOT 10
- DefaultScalaModule breaks deserialization of java classes HOT 13
- 2.16 jackson-databind deserialization changes have broken support for the scala.util.Either class HOT 1
- Collection of case classes deserialized as Collection of Map2 HOT 4
- Release 2.15.3 HOT 4
- Release 2.16.0-rc1 HOT 1
- error when deserializing yaml HOT 2
- Release 2.16.0 HOT 2
- release jackson-module-scala v2.12 for Scala 2.10 HOT 2
- Release 2.16.1 HOT 1
- Update `2.17` branch to `2.17.0-rc1-SNAPSHOT` HOT 2
- Release 2.15.4 HOT 1
- Release 2.17.0-rc1 HOT 1
- Release 2.16.2 HOT 2
- Release 2.17.0 HOT 2
- Performance regression with 2.17.x HOT 32
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-module-scala.