55import com .amazonaws .services .lambda .runtime .serialization .PojoSerializer ;
66import com .fasterxml .jackson .core .JsonFactory ;
77import com .fasterxml .jackson .core .JsonParser ;
8+ import com .fasterxml .jackson .core .json .JsonReadFeature ;
9+ import com .fasterxml .jackson .core .json .JsonWriteFeature ;
810import com .fasterxml .jackson .core .JsonGenerator ;
911import com .fasterxml .jackson .annotation .JsonInclude .Include ;
1012import com .fasterxml .jackson .databind .DeserializationConfig ;
1921import com .fasterxml .jackson .databind .PropertyNamingStrategy ;
2022import com .fasterxml .jackson .databind .SerializationConfig ;
2123import com .fasterxml .jackson .databind .SerializationFeature ;
24+ import com .fasterxml .jackson .databind .json .JsonMapper ;
2225import com .fasterxml .jackson .databind .module .SimpleModule ;
26+ import com .fasterxml .jackson .datatype .jdk8 .Jdk8Module ;
27+ import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
2328
2429import java .io .IOException ;
2530import 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