Skip to content

Commit e1dbd95

Browse files
authored
fix(serialization): Fix Joda time serialization for AWS events. (#2252)
1 parent 6e4701c commit e1dbd95

File tree

6 files changed

+204
-65
lines changed

6 files changed

+204
-65
lines changed

powertools-serialization/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
<groupId>com.fasterxml.jackson.core</groupId>
4848
<artifactId>jackson-databind</artifactId>
4949
</dependency>
50+
<dependency>
51+
<groupId>com.fasterxml.jackson.datatype</groupId>
52+
<artifactId>jackson-datatype-joda</artifactId>
53+
</dependency>
5054

5155
<!-- Test dependencies -->
5256
<dependency>

powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/JsonConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.fasterxml.jackson.databind.ObjectMapper;
2626
import com.fasterxml.jackson.databind.SerializationFeature;
2727
import com.fasterxml.jackson.databind.json.JsonMapper;
28+
import com.fasterxml.jackson.datatype.joda.JodaModule;
2829

2930
import io.burt.jmespath.JmesPath;
3031
import io.burt.jmespath.RuntimeConfiguration;
@@ -41,11 +42,13 @@ public final class JsonConfig {
4142
// Don't throw an exception when json has extra fields you are not serializing on.
4243
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
4344
// Ignore null values when writing json.
44-
.serializationInclusion(JsonInclude.Include.NON_NULL)
45+
.defaultPropertyInclusion(
46+
JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.USE_DEFAULTS))
4547
// Write times as a String instead of a Long so its human-readable.
4648
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
4749
// Sort fields in alphabetical order
4850
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
51+
.addModule(new JodaModule())
4952
.build();
5053

5154
private static final ThreadLocal<ObjectMapper> om = ThreadLocal.withInitial(objectMapperSupplier);

0 commit comments

Comments
 (0)