-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40819 from FWest98/fw/defaultmappercustomizer
Move standard `ObjectMapper` customization to dedicated Customizer
- Loading branch information
Showing
4 changed files
with
69 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ons/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/ConfigurationCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.quarkus.jackson.runtime; | ||
|
||
import java.time.ZoneId; | ||
import java.util.TimeZone; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.MapperFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
|
||
import io.quarkus.jackson.ObjectMapperCustomizer; | ||
|
||
@Singleton | ||
public class ConfigurationCustomizer implements ObjectMapperCustomizer { | ||
@Inject | ||
JacksonBuildTimeConfig jacksonBuildTimeConfig; | ||
|
||
@Inject | ||
JacksonSupport jacksonSupport; | ||
|
||
@Override | ||
public void customize(ObjectMapper objectMapper) { | ||
if (!jacksonBuildTimeConfig.failOnUnknownProperties) { | ||
// this feature is enabled by default, so we disable it | ||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | ||
} | ||
if (!jacksonBuildTimeConfig.failOnEmptyBeans) { | ||
// this feature is enabled by default, so we disable it | ||
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); | ||
} | ||
if (!jacksonBuildTimeConfig.writeDatesAsTimestamps) { | ||
// this feature is enabled by default, so we disable it | ||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | ||
} | ||
if (!jacksonBuildTimeConfig.writeDurationsAsTimestamps) { | ||
// this feature is enabled by default, so we disable it | ||
objectMapper.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); | ||
} | ||
if (jacksonBuildTimeConfig.acceptCaseInsensitiveEnums) { | ||
objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS); | ||
} | ||
JsonInclude.Include serializationInclusion = jacksonBuildTimeConfig.serializationInclusion.orElse(null); | ||
if (serializationInclusion != null) { | ||
objectMapper.setSerializationInclusion(serializationInclusion); | ||
} | ||
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)); | ||
} | ||
if (jacksonSupport.configuredNamingStrategy().isPresent()) { | ||
objectMapper.setPropertyNamingStrategy(jacksonSupport.configuredNamingStrategy().get()); | ||
} | ||
} | ||
|
||
@Override | ||
public int priority() { | ||
// we return the maximum possible priority to make sure these | ||
// settings are always applied first, before any other customizers. | ||
return ObjectMapperCustomizer.MAXIMUM_PRIORITY; | ||
} | ||
} |
37 changes: 0 additions & 37 deletions
37
...nsions/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/ObjectMapperProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters