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

Fn.conditionIf(...).toString() fails to serialize in Java #1984

Closed
robwettach opened this issue Mar 8, 2019 · 5 comments · Fixed by #2007 · May be fixed by MechanicalRock/account-reaper#6
Closed

Fn.conditionIf(...).toString() fails to serialize in Java #1984

robwettach opened this issue Mar 8, 2019 · 5 comments · Fixed by #2007 · May be fixed by MechanicalRock/account-reaper#6
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug.

Comments

@robwettach
Copy link

In CDK for Java 0.21.0, the FnIf condition extends Token, providing an implementation of toString() that performs as I expect: rendering the if-condition as a CloudFormation token string:

{
  "Fn::If": [
    "Condition",
    "IfTrue",
    "IfFalse"
  ]
}

After v0.21.0, specifically in the latest version 0.25.2, the new Fn.conditionIf method returns an IConditionExpression which does not extend Token or implement toString(). As such, when calling toString() on the result of Fn.conditionIf, which is required to pass the result of the condition to any "props" that expects a String, serializes the Java object directly:

"software.amazon.awscdk.IConditionExpression$Jsii$Proxy@3bbc39f8"

This makes CDK >0.21.0 unusable from Java if your stack expects to use "Fn::If". I believe that feat: cloudformation condition chaining (#1494) switched from returning an FnCondition, which extended CloudFormationToken, to returning IConditionExpression. Instead, it should simply have returned FnConditionBase, CloudFormationToken, or even just String.

robwettach pushed a commit to robwettach/cdk-1984-example that referenced this issue Mar 8, 2019
@robwettach
Copy link
Author

Here's a minimal example comparing CDK 0.21.0 to 0.25.2:
https://github.com/robwettach/cdk-1984-example

@zhangzhx
Copy link

I've seen this issue as well after upgrading to 0.25.

eladb pushed a commit that referenced this issue Mar 13, 2019
Expose the underlying `toString` in the `IConditionExpression` interface
so they can be embedded as string values in jsii languages.

Fixes #1984
@eladb eladb self-assigned this Mar 13, 2019
@eladb eladb added bug This issue is a bug. @aws-cdk/core Related to core CDK functionality labels Mar 13, 2019
@eladb
Copy link
Contributor

eladb commented Mar 13, 2019

Fix: #2007

eladb pushed a commit that referenced this issue Mar 13, 2019
Expose the underlying `toString` in the `IConditionExpression` interface
so they can be embedded as string values in jsii languages.

Fixes #1984
@williamwxz
Copy link

I have the same issue on version 0.22.x, I would like to have .toString() interface which can return either the value in true condition or false condition. Has it been fixed? Which version the issue was fixed?

@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 18, 2019

It will be released this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug.
Projects
None yet
5 participants