
com.amazonaws.services.lambda.runtime.api.client.runtimeapi.DtoSerializers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-lambda-java-runtime-interface-client Show documentation
Show all versions of aws-lambda-java-runtime-interface-client Show documentation
The AWS Lambda Java Runtime Interface Client implements the Lambda programming model for Java
The newest version!
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package com.amazonaws.services.lambda.runtime.api.client.runtimeapi;
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.ErrorRequest;
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.XRayErrorCause;
import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer;
import com.amazonaws.services.lambda.runtime.serialization.factories.GsonFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class DtoSerializers {
public static byte[] serialize(ErrorRequest error) {
return serialize(error, SingletonHelper.LAMBDA_ERROR_SERIALIZER);
}
public static byte[] serialize(XRayErrorCause xRayErrorCause) {
return serialize(xRayErrorCause, SingletonHelper.X_RAY_ERROR_CAUSE_SERIALIZER);
}
private static byte[] serialize(T pojo, PojoSerializer serializer) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
serializer.toJson(pojo, outputStream);
return outputStream.toByteArray();
} catch (IOException e) {
return null;
}
}
/**
* Implementation of
* Initialization-on-demand holder idiom
* This way the serializers will be loaded lazily
*/
private static class SingletonHelper {
private static final PojoSerializer LAMBDA_ERROR_SERIALIZER = GsonFactory.getInstance().getSerializer(ErrorRequest.class);
private static final PojoSerializer X_RAY_ERROR_CAUSE_SERIALIZER = GsonFactory.getInstance().getSerializer(XRayErrorCause.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy