Skip to content

Commit

Permalink
Merge pull request #20468 from geoand/jackson-simplification
Browse files Browse the repository at this point in the history
Simplify Jackson configuration
  • Loading branch information
geoand authored Sep 30, 2021
2 parents 4ef3f5d + 8f61378 commit f787bcf
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.GeneratedBeanBuildItem;
import io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
Expand All @@ -48,9 +45,6 @@
import io.quarkus.gizmo.MethodDescriptor;
import io.quarkus.gizmo.ResultHandle;
import io.quarkus.jackson.ObjectMapperCustomizer;
import io.quarkus.jackson.runtime.JacksonBuildTimeConfig;
import io.quarkus.jackson.runtime.JacksonConfigSupport;
import io.quarkus.jackson.runtime.JacksonRecorder;
import io.quarkus.jackson.runtime.ObjectMapperProducer;
import io.quarkus.jackson.spi.ClassPathJacksonModuleBuildItem;
import io.quarkus.jackson.spi.JacksonModuleBuildItem;
Expand Down Expand Up @@ -233,16 +227,6 @@ private void registerModuleIfOnClassPath(String moduleClassName,
}
}

@BuildStep
@Record(ExecutionTime.STATIC_INIT)
SyntheticBeanBuildItem pushConfigurationBean(JacksonRecorder jacksonRecorder,
JacksonBuildTimeConfig jacksonBuildTimeConfig) {
return SyntheticBeanBuildItem.configure(JacksonConfigSupport.class)
.scope(Singleton.class)
.supplier(jacksonRecorder.jacksonConfigSupport(jacksonBuildTimeConfig))
.done();
}

// Generate a ObjectMapperCustomizer bean that registers each serializer / deserializer as well as detected modules with the ObjectMapper
@BuildStep
void generateCustomizer(BuildProducer<GeneratedBeanBuildItem> generatedBeans,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import com.fasterxml.jackson.annotation.JsonInclude;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class JacksonBuildTimeConfig {

/**
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ public class ObjectMapperProducer {
@Singleton
@Produces
public ObjectMapper objectMapper(Instance<ObjectMapperCustomizer> customizers,
JacksonConfigSupport jacksonConfigSupport) {
JacksonBuildTimeConfig jacksonBuildTimeConfig) {
ObjectMapper objectMapper = new ObjectMapper();
if (!jacksonConfigSupport.isFailOnUnknownProperties()) {
if (!jacksonBuildTimeConfig.failOnUnknownProperties) {
// this feature is enabled by default, so we disable it
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
if (!jacksonConfigSupport.isFailOnEmptyBeans()) {
if (!jacksonBuildTimeConfig.failOnEmptyBeans) {
// this feature is enabled by default, so we disable it
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}
if (!jacksonConfigSupport.isWriteDatesAsTimestamps()) {
if (!jacksonBuildTimeConfig.writeDatesAsTimestamps) {
// this feature is enabled by default, so we disable it
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
if (jacksonConfigSupport.isAcceptCaseInsensitiveEnums()) {
if (jacksonBuildTimeConfig.acceptCaseInsensitiveEnums) {
objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
}
JsonInclude.Include serializationInclusion = jacksonConfigSupport.getSerializationInclusion();
JsonInclude.Include serializationInclusion = jacksonBuildTimeConfig.serializationInclusion.orElse(null);
if (serializationInclusion != null) {
objectMapper.setSerializationInclusion(serializationInclusion);
}
ZoneId zoneId = jacksonConfigSupport.getTimeZone();
ZoneId zoneId = jacksonBuildTimeConfig.timezone.orElse(null);
if ((zoneId != null) && !zoneId.getId().equals("UTC")) { // Jackson uses UTC as the default, so let's not reset it
objectMapper.setTimeZone(TimeZone.getTimeZone(zoneId));
}
Expand Down

0 comments on commit f787bcf

Please sign in to comment.