akka/akka-http

Jackson Marshallers / Unmarshallers should be configurable / use akka.serialization.jackson.JacksonObjectMapperProvider

Offen

#3.379 geöffnet am 20.07.2020

 (1 Kommentar) (2 Reaktionen) (0 zugewiesene Personen)Scala (598 Forks)batch import
1 - triagedhelp wantedt:marshalling

Repository-Metriken

Stars
 (1.311 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 10h) (2 gemergte PRs in 30 T)

Beschreibung

Currently the Jackson ObjectMapper in the akka.http.javadsl.marshallers.jackson.Jackson class creates a default object mapper which is not configurable. The only way to override its behaviour is by supplying a custom ObjectMapper everytime the marshaller/unmarshaller is used.

Akka already provides a way to customise Jackson configuration + retrieving a ObjectMapper through akka.serialization.jackson.JacksonObjectMapperProvider and the

akka.serialization.jackson {
    jackson-modules += "com.acme.MyJacksonModule"
}

configuration. The marshallers/unmarshallers should honour this configuration way. Ideally, we'd have a built-in

  public static Route extractObjectMapper(Function<ObjectMapper, Route> inner) {
    return extractActorSystem(sys -> {
      ObjectMapper objectMapper = JacksonObjectMapperProvider
          .get(sys)
          .getOrCreate("akka-http",
          Optional.empty());
      return provide(objectMapper, inner);
    });
  }

or similar.

Contributor Guide