8000 [Serverless] fix lambda event serialization by maxday · Pull Request #3645 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content

[Serverless] fix lambda event serialization#3645

Merged
maxday merged 11 commits intomasterfrom
maxday/fix-lambda-event-serialization
Jul 18, 2022
Merged

[Serverless] fix lambda event serialization#3645
maxday merged 11 commits intomasterfrom
maxday/fix-lambda-event-serialization

Conversation

@maxday
Copy link
Contributor
@maxday maxday commented Jul 7, 2022

What Does This Do

This PR fixes AWS Lambda event serialization when communication with the serverless extension
By default, moshi does not know how to serialize some nested types used in some AWS Events (SNS, SQS or S3)
We don't need those fields to be serialized to this PR just ignores them.

Motivation

Consistent JSON serialization across AWS events

@maxday maxday requested a review from a team as a code owner July 7, 2022 22:03
@devinsba devinsba added the tag: serverless Serverless support label Jul 8, 2022
delegate.toJson(writer, value);
}

public static <T> Factory newFactory(final String type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using typeToSkip here to match the field where it ends up would improve readability

@Override
public JsonAdapter<?> create(
Type requestedType, Set<? extends Annotation> annotations, Moshi moshi) {
if (null != requestedType && requestedType.toString().endsWith(type)) {
Copy link
Contributor
@mcculls mcculls Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wanted to match the check in the adapter then you could use:

Suggested change
if (null != requestedType && requestedType.toString().endsWith(type)) {
if (requestedType instanceof Class<?>
&& ((Class<?>) requestedType).getName().equals(typeToSkip)) {

which should be ok as the two current types are not generic, and so their reflected Type here would be Class.

Copy link
Contributor
@ygree ygree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for the adapter class name.

import java.lang.reflect.Type;
import java.util.Set;

public final class NoOpAdapter<T> extends JsonAdapter<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class name is not very clear. Maybe something like SkipTypeJsonSerializer would better outline the meaning of this adapter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely! renamed ✅

@maxday maxday merged commit 2285989 into master Jul 18, 2022
@maxday maxday deleted the maxday/fix-lambda-event-serialization branch July 18, 2022 13:48
@github-actions github-actions bot added this to the 0.105.0 milestone Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: serverless Serverless support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0