Skip to content

Commit d4cf118

Browse files
authored
1.1.0 lambda-java-serialization release (#404)
1 parent 8ae704d commit d4cf118

File tree

3 files changed

+97
-63
lines changed

3 files changed

+97
-63
lines changed

aws-lambda-java-serialization/RELEASE.CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### February 17, 2023
2+
`1.1.0`:
3+
- Update `jackson-databind` dependency from 2.13.4.1 to 2.14.2
4+
- Register `JavaTimeModule` and `Jdk8Module` modules to `jackson-databind`
5+
16
### February 09, 2023
27
`1.0.2`:
38
- Updated `gson` dependency from 2.8.9 to 2.10.1

aws-lambda-java-serialization/pom.xml

+15-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.amazonaws</groupId>
66
<artifactId>aws-lambda-java-serialization</artifactId>
7-
<version>1.0.2</version>
7+
<version>1.1.0</version>
88
<packaging>jar</packaging>
99

1010
<name>AWS Lambda Java Runtime Serialization</name>
@@ -32,6 +32,8 @@
3232
<maven.compiler.source>1.8</maven.compiler.source>
3333
<maven.compiler.target>1.8</maven.compiler.target>
3434
<relocation.prefix>com.amazonaws.lambda.thirdparty</relocation.prefix>
35+
<jackson.version>2.14.2</jackson.version>
36+
<gson.version>2.10.1</gson.version>
3537
<junit.version>5.9.1</junit.version>
3638
<owasp.version>7.3.2</owasp.version>
3739
</properties>
@@ -41,12 +43,22 @@
4143
<dependency>
4244
<groupId>com.fasterxml.jackson.core</groupId>
4345
<artifactId>jackson-databind</artifactId>
44-
<version>2.13.4.1</version>
46+
<version>${jackson.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.fasterxml.jackson.datatype</groupId>
50+
<artifactId>jackson-datatype-jsr310</artifactId>
51+
<version>${jackson.version}</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.fasterxml.jackson.datatype</groupId>
55+
<artifactId>jackson-datatype-jdk8</artifactId>
56+
<version>${jackson.version}</version>
4557
</dependency>
4658
<dependency>
4759
<groupId>com.google.code.gson</groupId>
4860
<artifactId>gson</artifactId>
49-
<version>2.10.1</version>
61+
<version>${gson.version}</version>
5062
</dependency>
5163
<dependency>
5264
<groupId>org.json</groupId>

aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java

+77-60
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer;
66
import com.fasterxml.jackson.core.JsonFactory;
77
import com.fasterxml.jackson.core.JsonParser;
8+
import com.fasterxml.jackson.core.json.JsonReadFeature;
9+
import com.fasterxml.jackson.core.json.JsonWriteFeature;
810
import com.fasterxml.jackson.core.JsonGenerator;
911
import com.fasterxml.jackson.annotation.JsonInclude.Include;
1012
import com.fasterxml.jackson.databind.DeserializationConfig;
@@ -19,7 +21,10 @@
1921
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
2022
import com.fasterxml.jackson.databind.SerializationConfig;
2123
import com.fasterxml.jackson.databind.SerializationFeature;
24+
import com.fasterxml.jackson.databind.json.JsonMapper;
2225
import com.fasterxml.jackson.databind.module.SimpleModule;
26+
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
27+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
2328

2429
import java.io.IOException;
2530
import java.io.OutputStream;
@@ -50,69 +55,72 @@ public ObjectMapper getMapper() {
5055

5156

5257
private static ObjectMapper createObjectMapper() {
53-
ObjectMapper mapper = new ObjectMapper(createJsonFactory());
58+
ObjectMapper mapper = JsonMapper.builder(createJsonFactory())
59+
.enable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) // this is default as of 2.2.0
60+
.enable(MapperFeature.AUTO_DETECT_FIELDS) // this is default as of 2.0.0
61+
.enable(MapperFeature.AUTO_DETECT_GETTERS) // this is default as of 2.0.0
62+
.enable(MapperFeature.AUTO_DETECT_IS_GETTERS) // this is default as of 2.0.0
63+
.enable(MapperFeature.AUTO_DETECT_SETTERS) // this is default as of 2.0.0
64+
.enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS) // this is default as of 2.0.0
65+
.enable(MapperFeature.USE_STD_BEAN_NAMING)
66+
.enable(MapperFeature.USE_ANNOTATIONS) // this is default as of 2.0.0
67+
.disable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) // this is default as of 2.5.0
68+
.disable(MapperFeature.AUTO_DETECT_CREATORS)
69+
.disable(MapperFeature.INFER_PROPERTY_MUTATORS)
70+
.disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) // this is default as of 2.0.0
71+
.disable(MapperFeature.USE_GETTERS_AS_SETTERS)
72+
.disable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME) // this is default as of 2.1.0
73+
.disable(MapperFeature.USE_STATIC_TYPING) // this is default as of 2.0.0
74+
.disable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS) // this is default as of 2.0.0
75+
.build();
76+
5477
SerializationConfig scfg = mapper.getSerializationConfig();
5578
scfg = scfg.withFeatures(
56-
SerializationFeature.FAIL_ON_SELF_REFERENCES,
57-
SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS,
58-
SerializationFeature.WRAP_EXCEPTIONS
59-
);
79+
SerializationFeature.FAIL_ON_SELF_REFERENCES, // this is default as of 2.4.0
80+
SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS, // this is default as of 2.4.0
81+
SerializationFeature.WRAP_EXCEPTIONS // this is default as of 2.0.0
82+
);
6083
scfg = scfg.withoutFeatures(
61-
SerializationFeature.CLOSE_CLOSEABLE,
84+
SerializationFeature.CLOSE_CLOSEABLE, // this is default as of 2.0.0
6285
SerializationFeature.EAGER_SERIALIZER_FETCH,
6386
SerializationFeature.FAIL_ON_EMPTY_BEANS,
6487
SerializationFeature.FLUSH_AFTER_WRITE_VALUE,
65-
SerializationFeature.INDENT_OUTPUT,
66-
SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
67-
SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID,
68-
SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS,
69-
SerializationFeature.WRAP_ROOT_VALUE
70-
);
88+
SerializationFeature.INDENT_OUTPUT, // this is default as of 2.5.0
89+
SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, // this is default as of 2.0.0
90+
SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID, // this is default as of 2.3.0
91+
SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS, // this is default as of 2.0.0
92+
SerializationFeature.WRAP_ROOT_VALUE // this is default as of 2.2.0
93+
);
7194
mapper.setConfig(scfg);
7295

7396
DeserializationConfig dcfg = mapper.getDeserializationConfig();
7497
dcfg = dcfg.withFeatures(
7598
DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT,
7699
DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
77100
DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
78-
DeserializationFeature.FAIL_ON_INVALID_SUBTYPE,
79-
DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS,
101+
DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, // this is default as of 2.2.0
102+
DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, // this is default as of 2.5.0
80103
DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL,
81104
DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS,
82-
DeserializationFeature.WRAP_EXCEPTIONS
83-
);
105+
DeserializationFeature.WRAP_EXCEPTIONS // this is default as of 2.0.0
106+
);
84107
dcfg = dcfg.withoutFeatures(
85-
DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES,
86-
DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES,
87-
DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS,
88-
DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY,
108+
DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, // this is default as of 2.3.0
109+
DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, // this is default as of 2.0.0
110+
DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, // this is default as of 2.0.0
111+
DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, // this is default as of 2.3.0
89112
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
90-
);
113+
);
91114
mapper.setConfig(dcfg);
92-
mapper.setSerializationInclusion(Include.NON_NULL); //NON_EMPTY?
93-
94-
mapper.enable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS);
95-
mapper.enable(MapperFeature.AUTO_DETECT_FIELDS);
96-
mapper.enable(MapperFeature.AUTO_DETECT_GETTERS);
97-
mapper.enable(MapperFeature.AUTO_DETECT_IS_GETTERS);
98-
mapper.enable(MapperFeature.AUTO_DETECT_SETTERS);
99-
mapper.enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);
100-
mapper.enable(MapperFeature.USE_STD_BEAN_NAMING);
101-
mapper.enable(MapperFeature.USE_ANNOTATIONS);
102-
103-
mapper.disable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
104-
mapper.disable(MapperFeature.AUTO_DETECT_CREATORS);
105-
mapper.disable(MapperFeature.INFER_PROPERTY_MUTATORS);
106-
mapper.disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
107-
mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
108-
mapper.disable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
109-
mapper.disable(MapperFeature.USE_STATIC_TYPING);
110-
mapper.disable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
115+
mapper.setSerializationInclusion(Include.NON_NULL);
111116

112117
SimpleModule module = new SimpleModule();
113118
module.addDeserializer(Void.class, new VoidDeserializer());
114119
mapper.registerModule(module);
115120

121+
mapper.registerModule(new JavaTimeModule());
122+
mapper.registerModule(new Jdk8Module());
123+
116124
return mapper;
117125
}
118126

@@ -138,33 +146,42 @@ public Void deserialize(JsonParser parser, DeserializationContext ctx) {
138146
}
139147

140148
private static JsonFactory createJsonFactory() {
141-
JsonFactory factory = new JsonFactory();
142-
//Json Parser enabled
143-
factory.enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS);
144-
factory.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS);
145-
factory.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
146-
factory.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER);
147-
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS);
148-
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
149+
JsonFactory factory = JsonFactory.builder()
150+
//Json Read enabled
151+
.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
152+
.enable(JsonReadFeature.ALLOW_LEADING_ZEROS_FOR_NUMBERS)
153+
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
154+
.enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)
155+
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS)
156+
.enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES)
157+
158+
//Json Read disabled
159+
.disable(JsonReadFeature.ALLOW_JAVA_COMMENTS) // this is default as of 2.10.0
160+
.disable(JsonReadFeature.ALLOW_YAML_COMMENTS) // this is default as of 2.10.0
161+
162+
//Json Write enabled
163+
.enable(JsonWriteFeature.QUOTE_FIELD_NAMES) // this is default as of 2.10.0
164+
.enable(JsonWriteFeature.WRITE_NAN_AS_STRINGS) // this is default as of 2.10.0
165+
166+
//Json Write disabled
167+
.disable(JsonWriteFeature.ESCAPE_NON_ASCII) // this is default as of 2.10.0
168+
.disable(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS) // this is default as of 2.10.0
169+
.build();
149170

150171
//Json Parser disabled
151-
factory.disable(JsonParser.Feature.ALLOW_COMMENTS);
152-
factory.disable(JsonParser.Feature.ALLOW_YAML_COMMENTS);
153172
factory.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
154173
factory.disable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
155174

156-
//Json generator enabled
175+
//Json Generator enabled
157176
factory.enable(JsonGenerator.Feature.IGNORE_UNKNOWN);
158-
factory.enable(JsonGenerator.Feature.QUOTE_FIELD_NAMES);
159-
factory.enable(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS);
160-
//Json generator disabled
177+
178+
//Json Generator disabled
161179
factory.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
162180
factory.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
163-
factory.disable(JsonGenerator.Feature.ESCAPE_NON_ASCII);
164181
factory.disable(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM);
165-
factory.disable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION);
166-
factory.disable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN);
167-
factory.disable(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS);
182+
factory.disable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION); // this is default as of 2.3.0
183+
factory.disable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); // this is default as of 2.3.0
184+
168185
return factory;
169186
}
170187

@@ -206,7 +223,7 @@ public void toJson(T value, OutputStream output) {
206223

207224
private static final class TypeSerializer extends InternalSerializer<Object> {
208225
public TypeSerializer(ObjectMapper mapper, JavaType type) {
209-
super(mapper.reader(type), mapper.writerFor(type));
226+
super(mapper.readerFor(type), mapper.writerFor(type));
210227
}
211228

212229
public TypeSerializer(ObjectMapper mapper, Type type) {
@@ -216,7 +233,7 @@ public TypeSerializer(ObjectMapper mapper, Type type) {
216233

217234
private static final class ClassSerializer<T> extends InternalSerializer<T> {
218235
public ClassSerializer(ObjectMapper mapper, Class<T> clazz) {
219-
super(mapper.reader(clazz), mapper.writerFor(clazz));
236+
super(mapper.readerFor(clazz), mapper.writerFor(clazz));
220237
}
221238
}
222239

0 commit comments

Comments
 (0)