-
Notifications
You must be signed in to change notification settings - Fork 915
Add union type design overview. #3119
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
static AttributeValue.Builder builder(); | ||
static fromS(String s); | ||
static fromN(String s); | ||
static fromB(String s); |
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.
Oops: SdkBytes b
void accept(AttributeValue.VoidVisitor visitor); | ||
<T> T accept(AttributeValue.Visitor<T> visitor); |
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 was wondering, should we have these? The customer can do a switch based on the type()
for something equivalent.
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.
Conclusion from review: They might be nice, but the void visitor is basically just a switch on the type() and the visitor is just a switch expression on the type() (added in Java 17). Admittedly, not a lot of customers are on 17 right now, but it would be good not to add it if we can avoid it. We'll end up waiting for customer feedback on this one before we add it.
|
||
## Union Type Definition | ||
|
||
We will follow the patterns set by `Document` and `JsonNode`, because the pattern used by `AudioStream` would not be backwards-compatible with existing types and does not function particularly well for union type members that are not structures. |
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.
Can you explain what the "...does not function particularly well for union type members that are not structures." means?
|
||
We currently implement friendly tagged unions in at least two external places within the SDK already: | ||
1. The `software.amazon.awssdk.core.document.Document` type. | ||
2. Event stream types, like TranscribeStreaming's `software.amazon.awssdk.services.transcribestreaming.model.AudioStream` type. |
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.
A better example (or in addition to) might be one of newer eventstreams like in Lex, which use the newer style of eventstream generation that supports 1:M of shapes to events
**After Changes** | ||
```java | ||
String result = attributeValue.visit(new AttributeValue.Visitor<String>(){ | ||
String visitS(String s) { return s; } | ||
String visitN(String n) { return n; } | ||
String visitB(SdkBytes b) { return b.asUtf8String(); } | ||
}); | ||
``` |
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.
Nice! I like this
```java | ||
attributeValue.visit(new AttributeValue.VoidVisitor() { | ||
void visitS(String s) { System.out.println(s); } | ||
void visitN(String n) { System.out.println(n); } | ||
void visitB(SdkBytes b) { System.out.println(b.asUtf8String()); } |
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.
Or using pattern matching for switch!
ea31722
to
dded97b
Compare
Service models marked as a union type have additional helper methods to take advantage of the knowledge that just one member is expected to be set. More information: #3119
Kudos, SonarCloud Quality Gate passed! |
* Added support for modeling union types. Service models marked as a union type have additional helper methods to take advantage of the knowledge that just one member is expected to be set. More information: #3119 * Addressed comments: two values set is now type() == null instead of type() == UNKNOWN_TO_SDK_VERSION.
…f39ca924d Pull request: release <- staging/661c5916-0027-4e4d-9671-d58f39ca924d
No description provided.