-
Notifications
You must be signed in to change notification settings - Fork 918
Refactoring for JSON marshalling/unmarshalling, support for JSON valu… #727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
40ca93f
to
0309bb7
Compare
0309bb7
to
59a4edb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the codegen generation tests updated?
@@ -64,7 +69,7 @@ public IntermediateModel( | |||
@JsonProperty("customizationConfig") CustomizationConfig customizationConfig, | |||
@JsonProperty("serviceExamples") ServiceExamples examples) { | |||
|
|||
this(metadata, operations, shapes, customizationConfig, examples, Collections.emptyMap(), Collections.emptyMap()); | |||
this(metadata, operations, shapes, customizationConfig, examples, Collections.emptyMap(), Collections.emptyMap(), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass in DefaultNamingStrategy instead of null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DefaultNamingStrategy requires the c2j models and we only have intermediate at this point.
|
||
|
||
try { | ||
T result = unmarshaller.unmarshall(pojoSupplier, response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case this will be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the payload is empty, I need to find a cleaner way to handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed. Can't remember how but it has lol
@@ -38,6 +39,6 @@ public void marshall(Void val, JsonMarshallerContext context, String paramName) | |||
* @param context Dependencies needed for marshalling. | |||
* @param paramName Optional param/field name. May be null in certain situations. | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add doc sdkField param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
@Override | ||
public Request<OrigRequestT> finishMarshalling() { | ||
private Object resolveValue(Object val, SdkField<?> marshallingInfo) { | ||
IdempotencyTrait trait = marshallingInfo.getTrait(IdempotencyTrait.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't understand why we are using IdempotencyTrait here>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline. The idempotency trait auto fills a value when none is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this has changed to the DefaultValueTrait to accomodate Glacier.
import software.amazon.awssdk.core.protocol.traits.LocationTrait; | ||
import software.amazon.awssdk.core.protocol.traits.Trait; | ||
|
||
public class SdkField<TypeT> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some javadocs as its used widely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added javadocs to all the relevant classes
private <V> V resolveValue(V val, MarshallingInfo<V> marshallingInfo) { | ||
return val == null && marshallingInfo.defaultValueSupplier() != null ? marshallingInfo.defaultValueSupplier().get() : val; | ||
private boolean isBinary(SdkField<?> field, Object val) { | ||
return isExplicitPayloadMember(field) && val instanceof SdkBytes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about InputStream type? Previously we considered both SdkBytes and InputStream as binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Streaming is no longer part of marshalling/unmarshalling. It's handled separately as it differs for sync vs async.
25da4f9
to
0569a80
Compare
bd9c8d7
to
34a78c6
Compare
34a78c6
to
339daa8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall lgtm. Minor feedback and looks like last commit broke the travis build
List<String> eventNames = EventStreamUtils.getEvents(eventStreamShape) | ||
.map(shape -> shape.getShapeName()) | ||
List<String> eventNames = EventStreamUtils.getEventMembers(eventStreamShape) | ||
.map(MemberModel::getC2jName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use shape name instead of c2j name? (incase we change the shape name in customizations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the member name as defined in the model since we use it for matching the event-type to the right unmarshaller.
|
||
private CodeBlock createLocationTrait(MemberModel m) { | ||
return CodeBlock.builder() | ||
// TODO will marshall and unmarshall location name ever differ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use the build pattern instead of create() here? So in case marshall and unmarshall location differ, we can add new methods without needing to deprecate create.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the member name as defined in the model since we use it for matching the event-type to the right unmarshaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replied to the wrong comment, +1 to the builder.
@@ -26,14 +27,21 @@ | |||
@SdkInternalApi | |||
public final class AwsStructuredCborFactory extends SdkStructuredCborFactory { | |||
|
|||
private static final ObjectMapper MAPPER = new ObjectMapper(CBOR_FACTORY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were talking about getting rid of object mapper to make sdk initialization faster. Is it possible to use jackson-jr classes instead of object mapper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I have an action item to replace this with something else. I was playing around with Jackson-JR and it doesn't seem to have the same capabilities as JsonNode so I'll likely have to write something custom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, not a blocker for this PR
*/ | ||
@SdkProtectedApi | ||
@ReviewBeforeRelease("Metadata in base result has been broken. Fix this and deal with AwsResponseHandlerAdapter") | ||
public final class NewJsonResponseHandler<T extends SdkPojo> implements HttpResponseHandler<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name feels little ambiguous. Are we going to replace the current JsonResponseHandler with this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah will do, meant to replace it.
jsonGenerator.writeFieldName(paramName); | ||
} | ||
TimestampFormatTrait trait = sdkField.getTrait(TimestampFormatTrait.class); | ||
if (trait != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar logic is present in ValueToStringConverter.FROM_INSTANT. Can you use it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They differ subtly in such a way that makes it hard to combine. For example we are always producing a String in ValueToString but we need to know how to write it to the JSON generator (i.e. as a string or as a string number). And we also have the fallback which is needed for CBOR.
…91bcdb2d Pull request: release <- staging/031a365b-dfef-4050-8bd9-a55a91bcdb2d
…e trait