-
Notifications
You must be signed in to change notification settings - Fork 882
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
Support auto construct lists #497
Conversation
@@ -123,6 +123,8 @@ | |||
|
|||
private Map<String, String> modelMarshallerDefaultValueSupplier; | |||
|
|||
private boolean useAutoConstructList = false; |
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.
I've gotten into an existential crisis now. What do auto-construct lists mean for the customer and the service in this context?
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.
Customers shouldn't have to worry about auto constructed lists, which is why I kept the return types as List<T>
.
For services, the only one I'm aware of currently is CloudFormation where we explicitly distinguish between a normal empty list and an auto constructed one and only send the normal list variety.
cfnRequestBuilder.withListMember(new ArrayList<>())
vs
cfnRequestBuilder.withListMember(null)
and internally we instantiate an auto constructed list.
@shorea probably has more insight on 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.
ELB definitely has some weirdness too. We should test that. I want to say KMS had something weird with Maps but I can't exactly remember.
An auto constructed list is essentially null for marshalling purposes. So for a JSON service we would omit the field entirely from the document if it's an auto constructed list.
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.
Do you think we could get away without having CloudFormation being a special case and just default to empty lists for responses? It's annoying for a customer to distinguish between empty list and null for responses, but having so much code for just CloudFormation feels like a lot of work.
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.
Do we know of any services where there is a semantic difference between null and empty lists in responses?
If the customer doesn't set anything on the request then we treat that as auto constructed list and send null on the wire (whatever that means for the protocol)
If the customer explicitly sets an empty list then we treat that as non-null and will send an empty list on the wire.
Inbound both null and empty lists will appear as empty lists to the customer with no real way to distinguish between them. If a service has a semantic difference between this (which they probably shouldn't) then we'd have to not auto construct for that service or perhaps just operation.
@Generated("software.amazon.awssdk:codegen") | ||
final class ListOfBlobsTypeCopier { | ||
static List<ByteBuffer> copy(Collection<ByteBuffer> listOfBlobsTypeParam) { | ||
if (listOfBlobsTypeParam == 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.
Do we need to check auto construct here to? Can we add a test to make sure that a POJO with an auto constructed list is preserved when we go from toBuilder and back?
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.
Hmm, we shouldn't have to. We use the model copiers on all builder setters (unless the param is something immutable like String
) and the builder constructor from the model class, so it should always be type of AutonConstructAwareList
, if that's what the customization config says.
Would making the field type AutoConstructAwareList
suffice?
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.
I just realized that we wrap in unmodifiableList
before returning which will mess with instanceof
checks we might do later in the marshallers. I'll need to make a few changes.
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.
Updated to do an instance check. Also added tests to verify this behavior
@@ -123,6 +123,8 @@ | |||
|
|||
private Map<String, String> modelMarshallerDefaultValueSupplier; | |||
|
|||
private boolean useAutoConstructList = false; |
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 default to true.
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.
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 want to go all in for auto construct unless we absolutely can't do it for whatever reason right? If we make it opt in via customization we'll forget to do it for a service and become inconsistent.
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.
Cool, wasn't aware of that but cool with it! Will update
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.
Updated to make auto construct lists the default
/** | ||
* @return {@code true} if this list was auto constructed. | ||
*/ | ||
boolean isAutoConstructed(); |
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.
Is this needed?
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.
Not sure what you mean. Do you mean this should just be a marker interface?
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.
Removed. Now using it basically as a marker interface.
isAutoConstructed = true; | ||
} | ||
|
||
public DefaultSdkAutoConstructAwareList(Collection<? extends T> other) { |
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.
Do we need these other constructors or can we just use the list implementation they pass in?
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.
I'd prefer to keep this since we make use of the copy constructor in in the model copier classes.
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.
Removed per the above comment.
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 looks good to me. Can you test with ELB and that cloudformation use case you mentioned?
@@ -0,0 +1,5 @@ | |||
{ | |||
"serviceInterfaceName" : "AmazonCodeGenerationJsonRpcCustomized", | |||
"packageSuffix" : "protdofjafoobarbazocol.jsonrpc.customized", |
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.
Lol what a name.
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.
LOL, I was trying to see if packageSuffix
was supported but it doesn't seem to be atm.
56b71b6
to
2d9076a
Compare
2d9076a
to
a61c5fb
Compare
…4f1e2565 Pull request: release <- staging/9e1b3fb5-5971-4be8-9f8b-0f434f1e2565
Description
Support auto construct lists. Only contains JSON marshaller changes ATM.
Motivation and Context
Support auto construct lists
Testing
Added new unit tests, reference files, and updated some existing ref files as well.
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsLicense