Skip to content

Commit

Permalink
Document reflection free Jackson serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Aug 2, 2024
1 parent 3724092 commit efd3ae1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/src/main/asciidoc/rest.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,12 @@ public User userPrivate() {
When the result the `userPublic` method is serialized, the `id` field will not be contained in the response as the `Public` view does not include it.
The result of `userPrivate` however will include the `id` as expected when serialized.

===== Reflection-free Jackson serialization

Out-of-the-box Jackson serialization converts objects into their JSON representation by introspecting them through a heavy use of reflection. However, the general Quarkus philosophy is to avoid reflection as much as possible, often replacing it with build time code generation. For this reason it is possible to automatically generate at build time implementations of the Jackson `StdSerializer`, one for each class to be converted in JSON. These generated serializers can be subsequently used by Quarkus at runtime to perform the JSON serialization of the objects returned by a REST endpoint without any use of reflection.

This feature is turned off by default, but it can be enabled by setting the configuration property `quarkus.rest.jackson.optimization.enable-reflection-free-serializers=true`.

===== Completely customized per method serialization/deserialization

There are times when you need to completely customize the serialization/deserialization of a POJO on a per Jakarta REST method basis or on a per Jakarta REST resource basis. For such use cases, you can use the `@io.quarkus.resteasy.reactive.jackson.CustomSerialization` and `@io.quarkus.resteasy.reactive.jackson.CustomDeserialization` annotations in the REST method or in the REST resource at class level. These annotations allow you to fully configure the `com.fasterxml.jackson.databind.ObjectWriter`/`com.fasterxml.jackson.databind.ObjectReader`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Jackson optimization configuration.
*/
@ConfigMapping(prefix = "quarkus.jackson.optimization")
@ConfigMapping(prefix = "quarkus.rest.jackson.optimization")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface JacksonOptimizationConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public JavaArchive get() {
.addAsResource(new StringAsset("admin-expression=admin\n" +
"user-expression=user\n" +
"birth-date-roles=alice,bob\n" +
"quarkus.jackson.optimization.enable-reflection-free-serializers=true\n"),
"quarkus.rest.jackson.optimization.enable-reflection-free-serializers=true\n"),
"application.properties");
}
});
Expand Down

0 comments on commit efd3ae1

Please sign in to comment.