-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kernel): Normalize empty structs to undefined (#416)
Upon deserializing objects from a "native" front-end (Java, .NET, ...), the kernel now interprets an empty value for a struct type (aka data type) as `undefined`, since front-ends that perform keyword lifting such as Python will not be able to distinguish between "no argument passed" and "an empty argument passed". Fixes #411
- Loading branch information
1 parent
0fb5f7c
commit a8ee954
Showing
19 changed files
with
453 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...n.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IOptionalStruct.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
[JsiiInterface(typeof(IOptionalStruct), "jsii-calc.OptionalStruct")] | ||
public interface IOptionalStruct | ||
{ | ||
[JsiiProperty("field", "{\"primitive\":\"string\",\"optional\":true}")] | ||
string Field | ||
{ | ||
get; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...on.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalStruct.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
[JsiiByValue] | ||
public class OptionalStruct : IOptionalStruct | ||
{ | ||
[JsiiProperty("field", "{\"primitive\":\"string\",\"optional\":true}", true)] | ||
public string Field | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalStructConsumer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
[JsiiClass(typeof(OptionalStructConsumer), "jsii-calc.OptionalStructConsumer", "[{\"name\":\"optionalStruct\",\"type\":{\"fqn\":\"jsii-calc.OptionalStruct\",\"optional\":true}}]")] | ||
public class OptionalStructConsumer : DeputyBase | ||
{ | ||
public OptionalStructConsumer(IOptionalStruct optionalStruct): base(new DeputyProps(new object[]{optionalStruct})) | ||
{ | ||
} | ||
|
||
protected OptionalStructConsumer(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
|
||
protected OptionalStructConsumer(DeputyProps props): base(props) | ||
{ | ||
} | ||
|
||
[JsiiProperty("parameterWasUndefined", "{\"primitive\":\"boolean\"}")] | ||
public virtual bool ParameterWasUndefined | ||
{ | ||
get => GetInstanceProperty<bool>(); | ||
} | ||
|
||
[JsiiProperty("fieldValue", "{\"primitive\":\"string\",\"optional\":true}")] | ||
public virtual string FieldValue | ||
{ | ||
get => GetInstanceProperty<string>(); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...II.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalStructProxy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
[JsiiTypeProxy(typeof(IOptionalStruct), "jsii-calc.OptionalStruct")] | ||
internal sealed class OptionalStructProxy : DeputyBase, IOptionalStruct | ||
{ | ||
private OptionalStructProxy(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
|
||
[JsiiProperty("field", "{\"primitive\":\"string\",\"optional\":true}")] | ||
public string Field | ||
{ | ||
get => GetInstanceProperty<string>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ed.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/OptionalStruct.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package software.amazon.jsii.tests.calculator; | ||
|
||
@javax.annotation.Generated(value = "jsii-pacmak") | ||
public interface OptionalStruct extends software.amazon.jsii.JsiiSerializable { | ||
java.lang.String getField(); | ||
|
||
/** | ||
* @return a {@link Builder} of {@link OptionalStruct} | ||
*/ | ||
static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* A builder for {@link OptionalStruct} | ||
*/ | ||
final class Builder { | ||
@javax.annotation.Nullable | ||
private java.lang.String _field; | ||
|
||
/** | ||
* Sets the value of Field | ||
* @param value the value to be set | ||
* @return {@code this} | ||
*/ | ||
public Builder withField(@javax.annotation.Nullable final java.lang.String value) { | ||
this._field = value; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the configured instance. | ||
* @return a new instance of {@link OptionalStruct} | ||
* @throws NullPointerException if any required attribute was not provided | ||
*/ | ||
public OptionalStruct build() { | ||
return new OptionalStruct() { | ||
@javax.annotation.Nullable | ||
private final java.lang.String $field = _field; | ||
|
||
@Override | ||
public java.lang.String getField() { | ||
return this.$field; | ||
} | ||
|
||
public com.fasterxml.jackson.databind.JsonNode $jsii$toJson() { | ||
com.fasterxml.jackson.databind.ObjectMapper om = software.amazon.jsii.JsiiObjectMapper.INSTANCE; | ||
com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); | ||
obj.set("field", om.valueToTree(this.getField())); | ||
return obj; | ||
} | ||
|
||
}; | ||
} | ||
} | ||
|
||
/** | ||
* A proxy class which represents a concrete javascript instance of this type. | ||
*/ | ||
final static class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.OptionalStruct { | ||
protected Jsii$Proxy(final software.amazon.jsii.JsiiObject.InitializationMode mode) { | ||
super(mode); | ||
} | ||
|
||
@Override | ||
@javax.annotation.Nullable | ||
public java.lang.String getField() { | ||
return this.jsiiGet("field", java.lang.String.class); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...calc/java/src/main/java/software/amazon/jsii/tests/calculator/OptionalStructConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package software.amazon.jsii.tests.calculator; | ||
|
||
@javax.annotation.Generated(value = "jsii-pacmak") | ||
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.OptionalStructConsumer") | ||
public class OptionalStructConsumer extends software.amazon.jsii.JsiiObject { | ||
protected OptionalStructConsumer(final software.amazon.jsii.JsiiObject.InitializationMode mode) { | ||
super(mode); | ||
} | ||
public OptionalStructConsumer(@javax.annotation.Nullable final software.amazon.jsii.tests.calculator.OptionalStruct optionalStruct) { | ||
super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii); | ||
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, java.util.stream.Stream.of(optionalStruct).toArray()); | ||
} | ||
public OptionalStructConsumer() { | ||
super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii); | ||
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); | ||
} | ||
|
||
public java.lang.Boolean getParameterWasUndefined() { | ||
return this.jsiiGet("parameterWasUndefined", java.lang.Boolean.class); | ||
} | ||
|
||
@javax.annotation.Nullable | ||
public java.lang.String getFieldValue() { | ||
return this.jsiiGet("fieldValue", java.lang.String.class); | ||
} | ||
} |
Oops, something went wrong.