[Serverless] fix lambda event serialization#3645
Merged
Conversation
mcculls
reviewed
Jul 9, 2022
dd-trace-core/src/main/java/datadog/trace/lambda/NoOpAdapter.java
Outdated
Show resolved
Hide resolved
mcculls
reviewed
Jul 11, 2022
| delegate.toJson(writer, value); | ||
| } | ||
|
|
||
| public static <T> Factory newFactory(final String type) { |
Contributor
There was a problem hiding this comment.
using typeToSkip here to match the field where it ends up would improve readability
mcculls
reviewed
Jul 11, 2022
| @Override | ||
| public JsonAdapter<?> create( | ||
| Type requestedType, Set<? extends Annotation> annotations, Moshi moshi) { | ||
| if (null != requestedType && requestedType.toString().endsWith(type)) { |
Contributor
There was a problem hiding this comment.
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.
mcculls
approved these changes
Jul 11, 2022
ygree
approved these changes
Jul 11, 2022
Contributor
There was a problem hiding this comment.
LGTM except for the adapter class name.
| import java.lang.reflect.Type; | ||
| import java.util.Set; | ||
|
|
||
| public final class NoOpAdapter<T> extends JsonAdapter<T> { |
Contributor
There was a problem hiding this comment.
The class name is not very clear. Maybe something like SkipTypeJsonSerializer would better outline the meaning of this adapter?
Contributor
Author
There was a problem hiding this comment.
Definitely! renamed ✅
maxday
added a commit
that referenced
this pull request
Jul 21, 2022
hokitam
pushed a commit
that referenced
this pull request
Jul 22, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a si
2FBA
ngle commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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