-
Notifications
You must be signed in to change notification settings - Fork 28
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
#patch Adding support for SdkBindingData[scala.Option[_]] #308
#patch Adding support for SdkBindingData[scala.Option[_]] #308
Conversation
Thank you for opening this pull request! 🙌 |
// is also super class of, for example, Option and Tuple | ||
// is also super class of, for example, Either or Try |
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.
Tuple is actually also just a case class and already works with the current implementation. The problem arises when there is an abstract Product type with several specific implementations like Either
or Try
map | ||
.get("value") | ||
.map(valueToParamValue(_, typeOf[S].typeArgs.head)) | ||
.asInstanceOf[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.
Since map.get(...)
already produces an Option, we can just go with that and map the inner value if present
.map(valueToParamValue(_, typeOf[S].typeArgs.head)) | ||
.asInstanceOf[S] | ||
else | ||
instantiateViaConstructor(clazz) |
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.
pulled out for readability
case t if t <:< typeOf[Product] && !(t =:= typeOf[Option[_]]) => | ||
case t if t <:< typeOf[Product] => |
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 check for avoiding Option was not successful before. It would need to use <:<
instead of =:=
.
807f899
to
b035cce
Compare
product.getClass.getDeclaredFields.map(_.getName).toList | ||
val methodNames = product.getClass.getDeclaredMethods.map(_.getName) | ||
product.getClass.getDeclaredFields | ||
.map(_.getName) | ||
.filter(methodNames.contains) | ||
.toList |
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 gave me ["serialVersionUUID", "value"]
for Option
which meant that the stored map used "serialVersionUUID" as the key for the value because this list is zipped with the productElements
.
Checking against the method names solves this also for case classes.
Signed-off-by: Jonathan Schuchart <[email protected]>
Signed-off-by: Jonathan Schuchart <[email protected]>
d0e0ab1
to
bab6ec6
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.
What do you think about add a specific of
factor for Options.
ofOption(value) => SdkBindingData[Option[_]]
and
of(Option(value)) => SdkBindingData[Option[_]]
to avoid to need to use the generics
How and why do you mean to avoid generics exactly? You'd still want a |
Congrats on merging your first pull request! 🎉 |
TL;DR
Adding explicit support for scala.Option type
Type
Are all requirements met?
Complete description
Added explicit special case for
Option
type when instantiating agenerics
literal type. Since support for any case classes in SdkLiteralTypes has been introduced, it's not immediately obvious why this worksbut this doesn't:
The latter case is especially useful for input classes to workflows and SdkTransforms of the form
The Option type can't be instantiated directly like a common case class, so it needs to be instantiated differently.
I believe the common usage of Option as a field type in scala classes justifies this special handling.
Tracking Issue
NA
Follow-up issue
NA