Skip to content

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

Merged
merged 9 commits into from
Oct 11, 2018

Conversation

shorea
Copy link
Contributor

@shorea shorea commented Sep 24, 2018

…e trait

@shorea shorea force-pushed the marshaller-refactor branch from 40ca93f to 0309bb7 Compare September 24, 2018 19:40
@shorea shorea force-pushed the marshaller-refactor branch from 0309bb7 to 59a4edb Compare September 24, 2018 20:00
Copy link
Contributor

@varunnvs92 varunnvs92 left a 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);
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.
*/
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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>

Copy link
Contributor Author

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.

Copy link
Contributor Author

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> {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@shorea shorea force-pushed the marshaller-refactor branch from 25da4f9 to 0569a80 Compare October 9, 2018 02:19
@shorea shorea force-pushed the marshaller-refactor branch from bd9c8d7 to 34a78c6 Compare October 9, 2018 23:53
@shorea shorea force-pushed the marshaller-refactor branch from 34a78c6 to 339daa8 Compare October 10, 2018 00:03
Copy link
Contributor

@varunnvs92 varunnvs92 left a 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)
Copy link
Contributor

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)

Copy link
Contributor Author

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?
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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> {
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@shorea shorea merged commit 8dccb12 into master Oct 11, 2018
@shorea shorea deleted the marshaller-refactor branch November 23, 2018 03:55
aws-sdk-java-automation added a commit that referenced this pull request Feb 6, 2020
…91bcdb2d

Pull request: release <- staging/031a365b-dfef-4050-8bd9-a55a91bcdb2d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants