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

Fix Json integration test and 2.8 highlights docs #10155

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,28 @@ class PlayBindingNameJavaJsonSpec extends JavaJsonSpec {
override val createObjectMapper: ObjectMapper = GuiceApplicationBuilder()
// should be able to use `.play.` namespace to override configurations
// for this `ObjectMapper`.
.configure("akka.serialization.jackson.play.serialization-features.WRITE_DURATIONS_AS_TIMESTAMPS" -> false)
.configure("akka.serialization.jackson.play.serialization-features.WRITE_DURATIONS_AS_TIMESTAMPS" -> true)
.build()
.injector
.instanceOf[ObjectMapper]

"ObjectMapper" should {
"respect the custom configuration" in new JsonScope {
Json.mapper().isEnabled(SerializationFeature.WRITE_DATES_WITH_ZONE_ID) must beFalse
Json.mapper().isEnabled(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) must beTrue
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://github.com/playframework/playframework/pull/9494/files#r400895796
This test is just not working. Not only we need to change to WRITE_DURATIONS_AS_TIMESTAMPS in the test, but also configure it to true, because false is the default anyway, so the test would still be useless.

}
}

// The dependency injected `ObjectMapper`
class ApplicationJavaJsonSpec extends JavaJsonSpec {
override val createObjectMapper: ObjectMapper = GuiceApplicationBuilder().build().injector.instanceOf[ObjectMapper]

"ObjectMapper" should {
"not render date types as timestamps by default" in new JsonScope {
Json.mapper().isEnabled(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) must beFalse
Json.mapper().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) must beFalse
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just confirms that WRITE_DURATIONS_AS_TIMESTAMPS is false by default and the above (now fixed) test makes sense now.

}

// Classic static `ObjectMapper` from play.libs.Json
Expand Down
4 changes: 2 additions & 2 deletions documentation/manual/releases/release28/Highlights28.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Jackson dependency was updated to the [latest minor release, 2.10](https://githu
Moreover, instead of providing its way to create and configure an `ObjectMapper`, which before Play 2.8 requires the user to write a custom binding, Play now uses Akka Jackson support to provide an `ObjectMapper`. So, it is now possible to add Jackson [Modules](https://doc.akka.io/docs/akka/2.6/serialization-jackson.html?language=scala#jackson-modules) and configure [Features](https://doc.akka.io/docs/akka/2.6/serialization-jackson.html?language=scala#additional-features) using `application.conf`. For example, if you want to add [Joda support](https://github.com/FasterXML/jackson-datatype-joda), you only need to add the following configuration:

```HOCON
akka.serialization.jackson.jackson-modules += "com.fasterxml.jackson.datatype.joda.JodaModule"
akka.serialization.jackson.play.jackson-modules += "com.fasterxml.jackson.datatype.joda.JodaModule"
```

And if you need to write numbers as strings, add the following configuration:

```HOCON
akka.serialization.jackson.serialization-features.WRITE_NUMBERS_AS_STRINGS=true
akka.serialization.jackson.play.serialization-features.WRITE_NUMBERS_AS_STRINGS=true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the play binding name here, because that's what we do in

as well. Just to keep things consistent.

More info here: https://doc.akka.io/docs/akka/2.6/serialization-jackson.html?language=scala#additional-configuration
Implementation here:

private val BINDING_NAME = "play"
lazy val get: ObjectMapper = {
val mapper = JacksonObjectMapperProvider.get(actorSystem).getOrCreate(BINDING_NAME, Option.empty)

```

### Guice support for Akka Actor Typed
Expand Down