jsii icon indicating copy to clipboard operation
jsii copied to clipboard

Structs + type unions don't work in Java

Open skinny85 opened this issue 4 years ago • 1 comments

:bug: Bug Report

Affected Languages

  • [ ] TypeScript or Javascript
  • [ ] Python
  • [x] Java
  • [ ] .NET (C#, F#, ...)
  • [ ] Go

General Information

  • JSII Version: 1.29.0
  • Platform: Darwin 186590cdb71d.ant.amazon.com 18.7.0 Darwin Kernel Version 18.7.0: Mon Mar 8 22:11:48 PST 2021; root:xnu-4903.278.65~1/RELEASE_X86_64 x86_64

What is the problem?

Structs that have type unions do not work correctly in Java.

For example:

        CfnBucket cfnBucket = CfnBucket.Builder.create(this, "CfnBucket").build();
        cfnBucket.setAccelerateConfiguration(CfnBucket.AccelerateConfigurationProperty.builder()
                .accelerationStatus("Suspended")
                .build());
        System.out.println(cfnBucket.getAccelerateConfiguration());

prints out:

software.amazon.jsii.JsiiObject@68a13400

while it clearly should return an instance of CfnBucket.AccelerateConfigurationProperty.

This is not a problem in other languages; for example, in Python:

        bucket = s3.CfnBucket(
            self, 'CfnBucket'
        )
        bucket.accelerate_configuration = s3.CfnBucket.AccelerateConfigurationProperty(
            acceleration_status='Suspended',
        )
        print(bucket.accelerate_configuration)

prints out:

AccelerateConfigurationProperty(acceleration_status='Suspended')

Which is what I would expect.

This is negatively impacting CDK customers that use Java (example: https://github.com/aws/aws-cdk/issues/12338).

skinny85 avatar May 21 '21 01:05 skinny85

Another example: a CDK customer is using the SES CfnTemplate class:

        CfnTemplate cfnTemplate = new CfnTemplate(this, "InvestigationSuccessTemplate", CfnTemplateProps.builder()
                .template(CfnTemplate.TemplateProperty.builder()
                        .templateName("SuccessfulInvestigation")
                        .htmlPart("html part")
                        .subjectPart("subject")
                        .build())
                .build());

They want to use ((CfnTemplate.TemplateProperty) cfnTemplate.getTemplate()).getTemplateName() in a further part of their CDK app, but they cannot, because cfnTemplate.getTemplate() returns JsiiObject, making cfnTemplate pretty much useless.

skinny85 avatar Sep 21 '21 18:09 skinny85