Skip to content
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

java (dotnet?) regression: unable to use structs with escape hatches #5066

Closed
eladb opened this issue Nov 17, 2019 · 2 comments · Fixed by aws/jsii#997 or #5103
Closed

java (dotnet?) regression: unable to use structs with escape hatches #5066

eladb opened this issue Nov 17, 2019 · 2 comments · Fixed by aws/jsii#997 or #5103
Assignees
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. p0

Comments

@eladb
Copy link
Contributor

eladb commented Nov 17, 2019

When passing in jsii generated structs to APIs that accept Object, the "$jsii.struct marker is retained. This means that users are not able to use jsii structs, for example, in property overrides, which is a regression from a previous version.

Reproduction Steps

Topic topic = Topic.Builder.create(this, "MyTopic").build();
CfnTopic cfnTopic = (CfnTopic) topic.getNode().getDefaultChild();
cfnTopic.addPropertyOverride("Subscriptions", Collections.singletonList(CfnTopic.SubscriptionProperty.builder()
        .endpoint("endpoint")
        .protocol("Foo")
        .build()));

Result is:

{
  "Type" : "AWS::SNS::Topic",
  "Properties" : {
    "Subscriptions" : [ {
      "$jsii.struct" : {
        "fqn" : "@aws-cdk/aws-sns.CfnTopic.SubscriptionProperty",
        "data" : {
          "endpoint" : "endpoint",
          "protocol" : "Foo"
        }
      }
    } ]
}

Expected:

{
  "Type" : "AWS::SNS::Topic",
  "Properties" : {
    "Subscriptions" : [ {
        "fqn" : "@aws-cdk/aws-sns.CfnTopic.SubscriptionProperty",
        "data" : {
          "endpoint" : "endpoint",
          "protocol" : "Foo"
        }
     }
   ]
}

Error Log

Environment

  • Framework Version: 1.16.3.DEVPREVIEW (jsii 0.20.6)
  • OS :
  • Language : Java (probably .NET as well)

Other


This is 🐛 Bug Report

@eladb eladb added bug This issue is a bug. p0 needs-triage This issue or PR still needs to be triaged. labels Nov 17, 2019
@eladb eladb changed the title java (and dotnet?) regression: unable to use structs with escape hatches java (dotnet?) regression: unable to use structs with escape hatches Nov 17, 2019
@eladb
Copy link
Contributor Author

eladb commented Nov 17, 2019

@RomainMuller why do we need to even tag structs? Isn't the whole point for them to be passed as simple values? There shouldn't be a difference between a struct and a JSON object sent over the wire.

@RomainMuller
Copy link
Contributor

RomainMuller commented Nov 18, 2019

The issue was when deserializing unions, a type hint was necessary in order to safely operate. There was a p0 bug that made SAM impossible to use without that. See aws/jsii#822 (which is what this behavior was introduced to fix)

eladb pushed a commit to aws/jsii that referenced this issue Nov 18, 2019
When a struct is serialized with a $jsii.struct decoration from a jsii host language and passed into a value typed `any`, the kernel ignored the decoration. This resulted in a malformed object passed to the javascript code.

This fix undecorates the object and continues to deserialize it as `any`.

Fixes aws/aws-cdk#5066
eladb pushed a commit to aws/jsii that referenced this issue Nov 18, 2019
When a struct is serialized with a $jsii.struct decoration from a jsii host language and passed into a value typed any, the kernel ignored the decoration. This resulted in a malformed object passed to the javascript code.

This fix undecorates the object and continues to deserialize it as a struct.

Also, increase kernel unit test coverage for serialization and deserialization of "any".

Fixes aws/aws-cdk#5066
eladb pushed a commit that referenced this issue Nov 19, 2019
Bug Fixes
- java: handle null-able collections correctly (#986) (e88e5e2), closes #4316
- jsii: unable to depend on modules with private declarations (#995) (08c4294), closes #994
- kernel: cannot pass decorated structs to kernel as "any" (#997) (2bd3183), closes #5066

Features
- jsii-config: introducing jsii-config (#981) (2bbf576), closes #904
- rosetta: extract and compile samples into "tablets" (#925) (eec44e1)
mergify bot pushed a commit that referenced this issue Nov 19, 2019
* feat: upgrade to jsii 0.20.7

Bug Fixes
- java: handle null-able collections correctly (#986) (e88e5e2), closes #4316
- jsii: unable to depend on modules with private declarations (#995) (08c4294), closes #994
- kernel: cannot pass decorated structs to kernel as "any" (#997) (2bd3183), closes #5066

Features
- jsii-config: introducing jsii-config (#981) (2bbf576), closes #904
- rosetta: extract and compile samples into "tablets" (#925) (eec44e1)

* fix broken code

* type a couple of more arrays

* fix another untyped array

* fix a couple more issues

* another untyped array

* more
eladb pushed a commit to cdklabs/decdk that referenced this issue Jan 18, 2022
* feat: upgrade to jsii 0.20.7

Bug Fixes
- java: handle null-able collections correctly (#986) (e88e5e2), closes aws/aws-cdk#4316
- jsii: unable to depend on modules with private declarations (#995) (08c4294), closes #994
- kernel: cannot pass decorated structs to kernel as "any" (#997) (2bd3183), closes aws/aws-cdk#5066

Features
- jsii-config: introducing jsii-config (#981) (2bbf576), closes #904
- rosetta: extract and compile samples into "tablets" (#925) (eec44e1)

* fix broken code

* type a couple of more arrays

* fix another untyped array

* fix a couple more issues

* another untyped array

* more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. p0
Projects
None yet
2 participants