From 4285e0a90dec0d916aa3ea6c480a5bb76a8f8b58 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov <75367056+smirnoal@users.noreply.github.com> Date: Fri, 13 Jan 2023 15:39:02 +0000 Subject: [PATCH 1/5] install buildx from docker/buildx-bin:latest --- .../codebuild-local/Dockerfile.agent | 22 +++++++------------ .../scripts/configure_multi_arch_env.sh | 12 ++-------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/aws-lambda-java-runtime-interface-client/test/integration/codebuild-local/Dockerfile.agent b/aws-lambda-java-runtime-interface-client/test/integration/codebuild-local/Dockerfile.agent index 9b31c16b..3dbdb3c6 100644 --- a/aws-lambda-java-runtime-interface-client/test/integration/codebuild-local/Dockerfile.agent +++ b/aws-lambda-java-runtime-interface-client/test/integration/codebuild-local/Dockerfile.agent @@ -1,20 +1,14 @@ FROM public.ecr.aws/amazoncorretto/amazoncorretto:8 -ARG ARCHITECTURE="amd64" - -ENV DOCKER_CLI_PLUGIN_DIR="/root/.docker/cli-plugins" -ENV PATH="$PATH:/tmp/apache-maven-3.8.7/bin" - +# Install docker and buildx extension RUN amazon-linux-extras enable docker && \ yum clean metadata && \ - yum install -y docker tar gzip unzip file wget + yum install -y docker tar gzip unzip file -RUN mkdir -p "${DOCKER_CLI_PLUGIN_DIR}" -RUN wget \ - "$(curl https://api.github.com/repos/docker/buildx/releases/latest | grep browser_download_url | grep "linux-${ARCHITECTURE}" | cut -d '"' -f 4)" \ - -O "${DOCKER_CLI_PLUGIN_DIR}"/docker-buildx -RUN chmod +x "${DOCKER_CLI_PLUGIN_DIR}"/docker-buildx +COPY --from=docker/buildx-bin:latest /buildx /usr/libexec/docker/cli-plugins/docker-buildx -WORKDIR /tmp -RUN curl -O https://archive.apache.org/dist/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz && \ - tar xf apache-maven-3.8.7-bin.tar.gz \ No newline at end of file +# Install maven from apache.org, as version in the yum repository doesn't support latest maven plugins +ENV PATH="$PATH:/apache-maven/bin" +RUN mkdir /apache-maven && \ + curl https://archive.apache.org/dist/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz | \ + tar -xz -C /apache-maven --strip-components 1 \ No newline at end of file diff --git a/aws-lambda-java-runtime-interface-client/test/integration/codebuild/scripts/configure_multi_arch_env.sh b/aws-lambda-java-runtime-interface-client/test/integration/codebuild/scripts/configure_multi_arch_env.sh index c4554805..76153f18 100755 --- a/aws-lambda-java-runtime-interface-client/test/integration/codebuild/scripts/configure_multi_arch_env.sh +++ b/aws-lambda-java-runtime-interface-client/test/integration/codebuild/scripts/configure_multi_arch_env.sh @@ -6,25 +6,17 @@ set -euo pipefail echo "Setting up multi-arch build environment" ARCHITECTURE=$(arch) if [[ "$ARCHITECTURE" == "x86_64" ]]; then - ARCHITECTURE_ALIAS="amd64" TARGET_EMULATOR="arm64" elif [[ "$ARCHITECTURE" == "aarch64" ]]; then - ARCHITECTURE_ALIAS="arm64" TARGET_EMULATOR="amd64" else echo "Architecture $ARCHITECTURE is not currently supported." exit 1 fi + echo "Installing ${TARGET_EMULATOR} emulator" docker pull public.ecr.aws/eks-distro-build-tooling/binfmt-misc:qemu-v6.1.0 docker run --rm --privileged public.ecr.aws/eks-distro-build-tooling/binfmt-misc:qemu-v6.1.0 --install ${TARGET_EMULATOR} -# Install buildx plugin only if not already present (i.e. it's installed for the local-agent) -if [[ ! -f "${DOCKER_CLI_PLUGIN_DIR}/docker-buildx" ]]; then - echo "docker-buildx not found, installing now" - mkdir -p "${DOCKER_CLI_PLUGIN_DIR}" - BUILDX_URL=$(curl https://api.github.com/repos/docker/buildx/releases/latest | grep browser_download_url | grep "linux-${ARCHITECTURE_ALIAS}" | cut -d '"' -f 4) - wget "${BUILDX_URL}" -O "${DOCKER_CLI_PLUGIN_DIR}"/docker-buildx - chmod +x "${DOCKER_CLI_PLUGIN_DIR}"/docker-buildx -fi echo "Setting docker build command to default to buildx" +echo "Docker buildx version: $(docker buildx version)" docker buildx install From c75c9dff9388ec5da47f227e1889e4e02d34f7b0 Mon Sep 17 00:00:00 2001 From: Andrea Culot <95755271+andclt@users.noreply.github.com> Date: Thu, 9 Feb 2023 09:42:05 +0000 Subject: [PATCH 2/5] 1.0.2 lambda-java-serialization release (#9) * Update gson to 2.10.1 --- aws-lambda-java-serialization/RELEASE.CHANGELOG.md | 4 ++++ aws-lambda-java-serialization/pom.xml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/aws-lambda-java-serialization/RELEASE.CHANGELOG.md b/aws-lambda-java-serialization/RELEASE.CHANGELOG.md index 76400917..f188ae7c 100644 --- a/aws-lambda-java-serialization/RELEASE.CHANGELOG.md +++ b/aws-lambda-java-serialization/RELEASE.CHANGELOG.md @@ -1,3 +1,7 @@ +### February 09, 2023 +`1.0.2`: +- Updated `gson` dependency from 2.8.9 to 2.10.1 + ### November 21, 2022 `1.0.1`: - Updated `jackson-databind` dependency from 2.12.6.1 to 2.13.4.1 diff --git a/aws-lambda-java-serialization/pom.xml b/aws-lambda-java-serialization/pom.xml index 468bf1a2..75c1ffef 100644 --- a/aws-lambda-java-serialization/pom.xml +++ b/aws-lambda-java-serialization/pom.xml @@ -4,7 +4,7 @@ com.amazonaws aws-lambda-java-serialization - 1.0.1 + 1.0.2 jar AWS Lambda Java Runtime Serialization @@ -46,7 +46,7 @@ com.google.code.gson gson - 2.8.9 + 2.10.1 org.json From 232eb6b99709478ad68538cd122acf570a3e4ba4 Mon Sep 17 00:00:00 2001 From: Andrea Culot Date: Thu, 9 Feb 2023 18:10:01 +0000 Subject: [PATCH 3/5] Consume aws-lambda-java-serialization 1.0.2 version --- aws-lambda-java-runtime-interface-client/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-lambda-java-runtime-interface-client/pom.xml b/aws-lambda-java-runtime-interface-client/pom.xml index 48a16dfe..5c680d65 100644 --- a/aws-lambda-java-runtime-interface-client/pom.xml +++ b/aws-lambda-java-runtime-interface-client/pom.xml @@ -56,7 +56,7 @@ com.amazonaws aws-lambda-java-serialization - 1.0.0 + 1.0.2 From 3d6fb0ebbcfbfab5a45449d1a1c2a412c87dae80 Mon Sep 17 00:00:00 2001 From: Andrea Culot <95755271+andclt@users.noreply.github.com> Date: Mon, 20 Feb 2023 18:58:57 +0000 Subject: [PATCH 4/5] Add ServiceLoader logic to load custom serializers (#10) * Add ServiceLoader logic to load custom serializers * 1.1.0 lambda-java-serialization release --- .../pom.xml | 4 +- .../api/client/EventHandlerLoader.java | 5 + .../api/client/PojoSerializerLoader.java | 77 ++++++++++ .../client/SerializersNotFoundException.java | 21 +++ ...TooManyServiceProvidersFoundException.java | 21 +++ aws-lambda-java-serialization/pom.xml | 18 ++- .../factories/JacksonFactory.java | 137 ++++++++++-------- 7 files changed, 218 insertions(+), 65 deletions(-) create mode 100644 aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/PojoSerializerLoader.java create mode 100644 aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/SerializersNotFoundException.java create mode 100644 aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/TooManyServiceProvidersFoundException.java diff --git a/aws-lambda-java-runtime-interface-client/pom.xml b/aws-lambda-java-runtime-interface-client/pom.xml index 5c680d65..7e87d099 100644 --- a/aws-lambda-java-runtime-interface-client/pom.xml +++ b/aws-lambda-java-runtime-interface-client/pom.xml @@ -51,12 +51,12 @@ com.amazonaws aws-lambda-java-core - 1.2.1 + 1.2.2 com.amazonaws aws-lambda-java-serialization - 1.0.2 + 1.1.0 diff --git a/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/EventHandlerLoader.java b/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/EventHandlerLoader.java index fc16d43f..65b95fcb 100644 --- a/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/EventHandlerLoader.java +++ b/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/EventHandlerLoader.java @@ -69,6 +69,11 @@ private EventHandlerLoader() { } */ @SuppressWarnings({"unchecked", "rawtypes"}) private static PojoSerializer getSerializer(Platform platform, Type type) { + PojoSerializer customSerializer = PojoSerializerLoader.getCustomerSerializer(type); + if (customSerializer != null) { + return customSerializer; + } + // if serializing a Class that is a Lambda supported event, use Jackson with customizations if (type instanceof Class) { Class clazz = ((Class)type); diff --git a/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/PojoSerializerLoader.java b/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/PojoSerializerLoader.java new file mode 100644 index 00000000..d4b4a5d1 --- /dev/null +++ b/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/PojoSerializerLoader.java @@ -0,0 +1,77 @@ +/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ + +package com.amazonaws.services.lambda.runtime.api.client; + +import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer; +import com.amazonaws.services.lambda.runtime.CustomPojoSerializer; + +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.Type; +import java.util.Iterator; +import java.util.ServiceConfigurationError; +import java.util.ServiceLoader; + +public class PojoSerializerLoader { + // The serializer obtained from the provider will always be the same so we can cache it as a filed. + private static CustomPojoSerializer customPojoSerializer; + // If Input and Output type are different, the runtime will try to search for a serializer twice due to + // the getSerializerCached method. Save the initialization state in order to search for the provider only once. + private static boolean initialized = false; + + private static CustomPojoSerializer loadSerializer() + throws ServiceConfigurationError, TooManyServiceProvidersFoundException { + + if (customPojoSerializer != null) { + return customPojoSerializer; + } + + ServiceLoader loader = ServiceLoader.load(CustomPojoSerializer.class, AWSLambda.customerClassLoader); + Iterator serializers = loader.iterator(); + + if (!serializers.hasNext()) { + initialized = true; + return null; + } + + customPojoSerializer = serializers.next(); + + if (serializers.hasNext()) { + throw new TooManyServiceProvidersFoundException( + "Too many serializers provided inside the META-INF/services folder, only one is allowed" + ); + } + + initialized = true; + return customPojoSerializer; + } + + public static PojoSerializer getCustomerSerializer(Type type) + throws SerializersNotFoundException { + + if (!initialized) { + customPojoSerializer = loadSerializer(); + } + + if (customPojoSerializer == null) { + return null; + } + + return new PojoSerializer() { + @Override + public Object fromJson(InputStream input) { + return customPojoSerializer.fromJson(input, type); + } + + @Override + public Object fromJson(String input) { + return customPojoSerializer.fromJson(input, type); + } + + @Override + public void toJson(Object value, OutputStream output) { + customPojoSerializer.toJson(value, output, type); + } + }; + } +} diff --git a/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/SerializersNotFoundException.java b/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/SerializersNotFoundException.java new file mode 100644 index 00000000..efd941cd --- /dev/null +++ b/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/SerializersNotFoundException.java @@ -0,0 +1,21 @@ +/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ + +package com.amazonaws.services.lambda.runtime.api.client; + +public class SerializersNotFoundException extends IllegalArgumentException { + public SerializersNotFoundException() { + + } + + public SerializersNotFoundException(String errorMessage) { + super(errorMessage); + } + + public SerializersNotFoundException(Throwable cause) { + super(cause); + } + + public SerializersNotFoundException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/TooManyServiceProvidersFoundException.java b/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/TooManyServiceProvidersFoundException.java new file mode 100644 index 00000000..c4b94e37 --- /dev/null +++ b/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/TooManyServiceProvidersFoundException.java @@ -0,0 +1,21 @@ +/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ + +package com.amazonaws.services.lambda.runtime.api.client; + +public class TooManyServiceProvidersFoundException extends RuntimeException { + public TooManyServiceProvidersFoundException() { + + } + + public TooManyServiceProvidersFoundException(String errorMessage) { + super(errorMessage); + } + + public TooManyServiceProvidersFoundException(Throwable cause) { + super(cause); + } + + public TooManyServiceProvidersFoundException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/aws-lambda-java-serialization/pom.xml b/aws-lambda-java-serialization/pom.xml index 75c1ffef..fd7724a4 100644 --- a/aws-lambda-java-serialization/pom.xml +++ b/aws-lambda-java-serialization/pom.xml @@ -4,7 +4,7 @@ com.amazonaws aws-lambda-java-serialization - 1.0.2 + 1.1.0 jar AWS Lambda Java Runtime Serialization @@ -32,6 +32,8 @@ 1.8 1.8 com.amazonaws.lambda.thirdparty + 2.14.2 + 2.10.1 5.9.1 7.3.2 @@ -41,12 +43,22 @@ com.fasterxml.jackson.core jackson-databind - 2.13.4.1 + ${jackson.version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + ${jackson.version} com.google.code.gson gson - 2.10.1 + ${gson.version} org.json diff --git a/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java b/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java index 7fccd2a5..f7c1dd4a 100644 --- a/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java +++ b/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java @@ -5,6 +5,8 @@ import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.json.JsonReadFeature; +import com.fasterxml.jackson.core.json.JsonWriteFeature; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.DeserializationConfig; @@ -19,7 +21,10 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.SerializationConfig; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.io.IOException; import java.io.OutputStream; @@ -50,24 +55,42 @@ public ObjectMapper getMapper() { private static ObjectMapper createObjectMapper() { - ObjectMapper mapper = new ObjectMapper(createJsonFactory()); + ObjectMapper mapper = JsonMapper.builder(createJsonFactory()) + .enable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) // this is default as of 2.2.0 + .enable(MapperFeature.AUTO_DETECT_FIELDS) // this is default as of 2.0.0 + .enable(MapperFeature.AUTO_DETECT_GETTERS) // this is default as of 2.0.0 + .enable(MapperFeature.AUTO_DETECT_IS_GETTERS) // this is default as of 2.0.0 + .enable(MapperFeature.AUTO_DETECT_SETTERS) // this is default as of 2.0.0 + .enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS) // this is default as of 2.0.0 + .enable(MapperFeature.USE_STD_BEAN_NAMING) + .enable(MapperFeature.USE_ANNOTATIONS) // this is default as of 2.0.0 + .disable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) // this is default as of 2.5.0 + .disable(MapperFeature.AUTO_DETECT_CREATORS) + .disable(MapperFeature.INFER_PROPERTY_MUTATORS) + .disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) // this is default as of 2.0.0 + .disable(MapperFeature.USE_GETTERS_AS_SETTERS) + .disable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME) // this is default as of 2.1.0 + .disable(MapperFeature.USE_STATIC_TYPING) // this is default as of 2.0.0 + .disable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS) // this is default as of 2.0.0 + .build(); + SerializationConfig scfg = mapper.getSerializationConfig(); scfg = scfg.withFeatures( - SerializationFeature.FAIL_ON_SELF_REFERENCES, - SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS, - SerializationFeature.WRAP_EXCEPTIONS - ); + SerializationFeature.FAIL_ON_SELF_REFERENCES, // this is default as of 2.4.0 + SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS, // this is default as of 2.4.0 + SerializationFeature.WRAP_EXCEPTIONS // this is default as of 2.0.0 + ); scfg = scfg.withoutFeatures( - SerializationFeature.CLOSE_CLOSEABLE, + SerializationFeature.CLOSE_CLOSEABLE, // this is default as of 2.0.0 SerializationFeature.EAGER_SERIALIZER_FETCH, SerializationFeature.FAIL_ON_EMPTY_BEANS, SerializationFeature.FLUSH_AFTER_WRITE_VALUE, - SerializationFeature.INDENT_OUTPUT, - SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, - SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID, - SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS, - SerializationFeature.WRAP_ROOT_VALUE - ); + SerializationFeature.INDENT_OUTPUT, // this is default as of 2.5.0 + SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, // this is default as of 2.0.0 + SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID, // this is default as of 2.3.0 + SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS, // this is default as of 2.0.0 + SerializationFeature.WRAP_ROOT_VALUE // this is default as of 2.2.0 + ); mapper.setConfig(scfg); DeserializationConfig dcfg = mapper.getDeserializationConfig(); @@ -75,44 +98,29 @@ private static ObjectMapper createObjectMapper() { DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, - DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, - DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, + DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, // this is default as of 2.2.0 + DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, // this is default as of 2.5.0 DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, - DeserializationFeature.WRAP_EXCEPTIONS - ); + DeserializationFeature.WRAP_EXCEPTIONS // this is default as of 2.0.0 + ); dcfg = dcfg.withoutFeatures( - DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, - DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, - DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, - DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, + DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, // this is default as of 2.3.0 + DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, // this is default as of 2.0.0 + DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, // this is default as of 2.0.0 + DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, // this is default as of 2.3.0 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES - ); + ); mapper.setConfig(dcfg); - mapper.setSerializationInclusion(Include.NON_NULL); //NON_EMPTY? - - mapper.enable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS); - mapper.enable(MapperFeature.AUTO_DETECT_FIELDS); - mapper.enable(MapperFeature.AUTO_DETECT_GETTERS); - mapper.enable(MapperFeature.AUTO_DETECT_IS_GETTERS); - mapper.enable(MapperFeature.AUTO_DETECT_SETTERS); - mapper.enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS); - mapper.enable(MapperFeature.USE_STD_BEAN_NAMING); - mapper.enable(MapperFeature.USE_ANNOTATIONS); - - mapper.disable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); - mapper.disable(MapperFeature.AUTO_DETECT_CREATORS); - mapper.disable(MapperFeature.INFER_PROPERTY_MUTATORS); - mapper.disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); - mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS); - mapper.disable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME); - mapper.disable(MapperFeature.USE_STATIC_TYPING); - mapper.disable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS); + mapper.setSerializationInclusion(Include.NON_NULL); SimpleModule module = new SimpleModule(); module.addDeserializer(Void.class, new VoidDeserializer()); mapper.registerModule(module); + mapper.registerModule(new JavaTimeModule()); + mapper.registerModule(new Jdk8Module()); + return mapper; } @@ -138,33 +146,42 @@ public Void deserialize(JsonParser parser, DeserializationContext ctx) { } private static JsonFactory createJsonFactory() { - JsonFactory factory = new JsonFactory(); - //Json Parser enabled - factory.enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS); - factory.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS); - factory.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); - factory.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER); - factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS); - factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); + JsonFactory factory = JsonFactory.builder() + //Json Read enabled + .enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS) + .enable(JsonReadFeature.ALLOW_LEADING_ZEROS_FOR_NUMBERS) + .enable(JsonReadFeature.ALLOW_SINGLE_QUOTES) + .enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER) + .enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS) + .enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES) + + //Json Read disabled + .disable(JsonReadFeature.ALLOW_JAVA_COMMENTS) // this is default as of 2.10.0 + .disable(JsonReadFeature.ALLOW_YAML_COMMENTS) // this is default as of 2.10.0 + + //Json Write enabled + .enable(JsonWriteFeature.QUOTE_FIELD_NAMES) // this is default as of 2.10.0 + .enable(JsonWriteFeature.WRITE_NAN_AS_STRINGS) // this is default as of 2.10.0 + + //Json Write disabled + .disable(JsonWriteFeature.ESCAPE_NON_ASCII) // this is default as of 2.10.0 + .disable(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS) // this is default as of 2.10.0 + .build(); //Json Parser disabled - factory.disable(JsonParser.Feature.ALLOW_COMMENTS); - factory.disable(JsonParser.Feature.ALLOW_YAML_COMMENTS); factory.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); factory.disable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION); - //Json generator enabled + //Json Generator enabled factory.enable(JsonGenerator.Feature.IGNORE_UNKNOWN); - factory.enable(JsonGenerator.Feature.QUOTE_FIELD_NAMES); - factory.enable(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS); - //Json generator disabled + + //Json Generator disabled factory.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT); factory.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); - factory.disable(JsonGenerator.Feature.ESCAPE_NON_ASCII); factory.disable(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM); - factory.disable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION); - factory.disable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); - factory.disable(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS); + factory.disable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION); // this is default as of 2.3.0 + factory.disable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); // this is default as of 2.3.0 + return factory; } @@ -206,7 +223,7 @@ public void toJson(T value, OutputStream output) { private static final class TypeSerializer extends InternalSerializer { public TypeSerializer(ObjectMapper mapper, JavaType type) { - super(mapper.reader(type), mapper.writerFor(type)); + super(mapper.readerFor(type), mapper.writerFor(type)); } public TypeSerializer(ObjectMapper mapper, Type type) { @@ -216,7 +233,7 @@ public TypeSerializer(ObjectMapper mapper, Type type) { private static final class ClassSerializer extends InternalSerializer { public ClassSerializer(ObjectMapper mapper, Class clazz) { - super(mapper.reader(clazz), mapper.writerFor(clazz)); + super(mapper.readerFor(clazz), mapper.writerFor(clazz)); } } From 775c7087306832de325e8b15fe9c36a229991259 Mon Sep 17 00:00:00 2001 From: Andrea Culot <95755271+andclt@users.noreply.github.com> Date: Fri, 24 Feb 2023 16:16:23 +0000 Subject: [PATCH 5/5] Rollback Jackson updates (#12) --- .../RELEASE.CHANGELOG.md | 10 +- aws-lambda-java-serialization/pom.xml | 16 +- .../factories/JacksonFactory.java | 137 ++++++++---------- 3 files changed, 66 insertions(+), 97 deletions(-) diff --git a/aws-lambda-java-serialization/RELEASE.CHANGELOG.md b/aws-lambda-java-serialization/RELEASE.CHANGELOG.md index f188ae7c..3fd99c70 100644 --- a/aws-lambda-java-serialization/RELEASE.CHANGELOG.md +++ b/aws-lambda-java-serialization/RELEASE.CHANGELOG.md @@ -1,10 +1,6 @@ -### February 09, 2023 -`1.0.2`: -- Updated `gson` dependency from 2.8.9 to 2.10.1 - -### November 21, 2022 -`1.0.1`: -- Updated `jackson-databind` dependency from 2.12.6.1 to 2.13.4.1 +### February 24, 2023 +`1.0.1-java17`: +- Add support for tumbling windows events ### December 01, 2020 `1.0.0`: diff --git a/aws-lambda-java-serialization/pom.xml b/aws-lambda-java-serialization/pom.xml index fd7724a4..1f0be649 100644 --- a/aws-lambda-java-serialization/pom.xml +++ b/aws-lambda-java-serialization/pom.xml @@ -4,7 +4,7 @@ com.amazonaws aws-lambda-java-serialization - 1.1.0 + 1.0.1-java17 jar AWS Lambda Java Runtime Serialization @@ -32,8 +32,8 @@ 1.8 1.8 com.amazonaws.lambda.thirdparty - 2.14.2 - 2.10.1 + 2.10.5.1 + 2.8.9 5.9.1 7.3.2 @@ -45,16 +45,6 @@ jackson-databind ${jackson.version} - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - ${jackson.version} - - - com.fasterxml.jackson.datatype - jackson-datatype-jdk8 - ${jackson.version} - com.google.code.gson gson diff --git a/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java b/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java index f7c1dd4a..7fccd2a5 100644 --- a/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java +++ b/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/factories/JacksonFactory.java @@ -5,8 +5,6 @@ import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.json.JsonReadFeature; -import com.fasterxml.jackson.core.json.JsonWriteFeature; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.DeserializationConfig; @@ -21,10 +19,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.SerializationConfig; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.io.IOException; import java.io.OutputStream; @@ -55,42 +50,24 @@ public ObjectMapper getMapper() { private static ObjectMapper createObjectMapper() { - ObjectMapper mapper = JsonMapper.builder(createJsonFactory()) - .enable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) // this is default as of 2.2.0 - .enable(MapperFeature.AUTO_DETECT_FIELDS) // this is default as of 2.0.0 - .enable(MapperFeature.AUTO_DETECT_GETTERS) // this is default as of 2.0.0 - .enable(MapperFeature.AUTO_DETECT_IS_GETTERS) // this is default as of 2.0.0 - .enable(MapperFeature.AUTO_DETECT_SETTERS) // this is default as of 2.0.0 - .enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS) // this is default as of 2.0.0 - .enable(MapperFeature.USE_STD_BEAN_NAMING) - .enable(MapperFeature.USE_ANNOTATIONS) // this is default as of 2.0.0 - .disable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) // this is default as of 2.5.0 - .disable(MapperFeature.AUTO_DETECT_CREATORS) - .disable(MapperFeature.INFER_PROPERTY_MUTATORS) - .disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) // this is default as of 2.0.0 - .disable(MapperFeature.USE_GETTERS_AS_SETTERS) - .disable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME) // this is default as of 2.1.0 - .disable(MapperFeature.USE_STATIC_TYPING) // this is default as of 2.0.0 - .disable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS) // this is default as of 2.0.0 - .build(); - + ObjectMapper mapper = new ObjectMapper(createJsonFactory()); SerializationConfig scfg = mapper.getSerializationConfig(); scfg = scfg.withFeatures( - SerializationFeature.FAIL_ON_SELF_REFERENCES, // this is default as of 2.4.0 - SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS, // this is default as of 2.4.0 - SerializationFeature.WRAP_EXCEPTIONS // this is default as of 2.0.0 - ); + SerializationFeature.FAIL_ON_SELF_REFERENCES, + SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS, + SerializationFeature.WRAP_EXCEPTIONS + ); scfg = scfg.withoutFeatures( - SerializationFeature.CLOSE_CLOSEABLE, // this is default as of 2.0.0 + SerializationFeature.CLOSE_CLOSEABLE, SerializationFeature.EAGER_SERIALIZER_FETCH, SerializationFeature.FAIL_ON_EMPTY_BEANS, SerializationFeature.FLUSH_AFTER_WRITE_VALUE, - SerializationFeature.INDENT_OUTPUT, // this is default as of 2.5.0 - SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, // this is default as of 2.0.0 - SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID, // this is default as of 2.3.0 - SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS, // this is default as of 2.0.0 - SerializationFeature.WRAP_ROOT_VALUE // this is default as of 2.2.0 - ); + SerializationFeature.INDENT_OUTPUT, + SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, + SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID, + SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS, + SerializationFeature.WRAP_ROOT_VALUE + ); mapper.setConfig(scfg); DeserializationConfig dcfg = mapper.getDeserializationConfig(); @@ -98,29 +75,44 @@ private static ObjectMapper createObjectMapper() { DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, - DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, // this is default as of 2.2.0 - DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, // this is default as of 2.5.0 + DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, + DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, - DeserializationFeature.WRAP_EXCEPTIONS // this is default as of 2.0.0 - ); + DeserializationFeature.WRAP_EXCEPTIONS + ); dcfg = dcfg.withoutFeatures( - DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, // this is default as of 2.3.0 - DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, // this is default as of 2.0.0 - DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, // this is default as of 2.0.0 - DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, // this is default as of 2.3.0 + DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, + DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, + DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, + DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES - ); + ); mapper.setConfig(dcfg); - mapper.setSerializationInclusion(Include.NON_NULL); + mapper.setSerializationInclusion(Include.NON_NULL); //NON_EMPTY? + + mapper.enable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS); + mapper.enable(MapperFeature.AUTO_DETECT_FIELDS); + mapper.enable(MapperFeature.AUTO_DETECT_GETTERS); + mapper.enable(MapperFeature.AUTO_DETECT_IS_GETTERS); + mapper.enable(MapperFeature.AUTO_DETECT_SETTERS); + mapper.enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS); + mapper.enable(MapperFeature.USE_STD_BEAN_NAMING); + mapper.enable(MapperFeature.USE_ANNOTATIONS); + + mapper.disable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); + mapper.disable(MapperFeature.AUTO_DETECT_CREATORS); + mapper.disable(MapperFeature.INFER_PROPERTY_MUTATORS); + mapper.disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); + mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS); + mapper.disable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME); + mapper.disable(MapperFeature.USE_STATIC_TYPING); + mapper.disable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS); SimpleModule module = new SimpleModule(); module.addDeserializer(Void.class, new VoidDeserializer()); mapper.registerModule(module); - mapper.registerModule(new JavaTimeModule()); - mapper.registerModule(new Jdk8Module()); - return mapper; } @@ -146,42 +138,33 @@ public Void deserialize(JsonParser parser, DeserializationContext ctx) { } private static JsonFactory createJsonFactory() { - JsonFactory factory = JsonFactory.builder() - //Json Read enabled - .enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS) - .enable(JsonReadFeature.ALLOW_LEADING_ZEROS_FOR_NUMBERS) - .enable(JsonReadFeature.ALLOW_SINGLE_QUOTES) - .enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER) - .enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS) - .enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES) - - //Json Read disabled - .disable(JsonReadFeature.ALLOW_JAVA_COMMENTS) // this is default as of 2.10.0 - .disable(JsonReadFeature.ALLOW_YAML_COMMENTS) // this is default as of 2.10.0 - - //Json Write enabled - .enable(JsonWriteFeature.QUOTE_FIELD_NAMES) // this is default as of 2.10.0 - .enable(JsonWriteFeature.WRITE_NAN_AS_STRINGS) // this is default as of 2.10.0 - - //Json Write disabled - .disable(JsonWriteFeature.ESCAPE_NON_ASCII) // this is default as of 2.10.0 - .disable(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS) // this is default as of 2.10.0 - .build(); + JsonFactory factory = new JsonFactory(); + //Json Parser enabled + factory.enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS); + factory.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS); + factory.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); + factory.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER); + factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS); + factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); //Json Parser disabled + factory.disable(JsonParser.Feature.ALLOW_COMMENTS); + factory.disable(JsonParser.Feature.ALLOW_YAML_COMMENTS); factory.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); factory.disable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION); - //Json Generator enabled + //Json generator enabled factory.enable(JsonGenerator.Feature.IGNORE_UNKNOWN); - - //Json Generator disabled + factory.enable(JsonGenerator.Feature.QUOTE_FIELD_NAMES); + factory.enable(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS); + //Json generator disabled factory.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT); factory.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); + factory.disable(JsonGenerator.Feature.ESCAPE_NON_ASCII); factory.disable(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM); - factory.disable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION); // this is default as of 2.3.0 - factory.disable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); // this is default as of 2.3.0 - + factory.disable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION); + factory.disable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); + factory.disable(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS); return factory; } @@ -223,7 +206,7 @@ public void toJson(T value, OutputStream output) { private static final class TypeSerializer extends InternalSerializer { public TypeSerializer(ObjectMapper mapper, JavaType type) { - super(mapper.readerFor(type), mapper.writerFor(type)); + super(mapper.reader(type), mapper.writerFor(type)); } public TypeSerializer(ObjectMapper mapper, Type type) { @@ -233,7 +216,7 @@ public TypeSerializer(ObjectMapper mapper, Type type) { private static final class ClassSerializer extends InternalSerializer { public ClassSerializer(ObjectMapper mapper, Class clazz) { - super(mapper.readerFor(clazz), mapper.writerFor(clazz)); + super(mapper.reader(clazz), mapper.writerFor(clazz)); } }