如何确定java aws cdk中software.amazon.jsii.jsiiobject的类型?

5q4ezhmt  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(429)

如何确定java aws cdk中software.amazon.jsii.jsiiobject的底层aws cdk类型?
在aws cdk中,每个jsiiobject都被强制转换为aws cdk类型,例如aws::ec2::securitygroupingress
例如,getsecuritygroupingress()是aws cdk中的一个方法,它返回一个jssiobject,该jssiobject在下面的代码中被强制转换到(list)中。然而,由于文档表明对象中返回的类型,我不清楚对象中包含的jssiobject表示什么aws cdk类型。

CfnSecurityGroup cfnSecurityGroup = (CfnSecurityGroup) resource_SecurityGroup.getCfnresource();

 if (cfnSecurityGroup.getSecurityGroupIngress() != null) {

    List<CfnSecurityGroupIngress> cfnSecurityGroupIngress = (List<CfnSecurityGroupIngress>) cfnSecurityGroup.getSecurityGroupIngress();

如何确定jsiiobject的aws cdk类型?
Maven

<dependency>
        <groupId>software.amazon.awscdk</groupId>
        <artifactId>cdk-cloudformation-include</artifactId>
        <version>1.79.0</version>
    </dependency>

敬孔戴

4si2a6ki

4si2a6ki1#

这在某些情况下可以工作,例如上面的示例,但是一些jsiiobject不容易转换为jsonnode,例如,可能表示一个列表。

public void PrintObjectAsJson(Object obj) throws IOException {

    JsiiObject J = (JsiiObject) obj;
    JsonNode jsonNode = (JsonNode) J.$jsii$toJson();
    ObjectMapper mapper = new ObjectMapper();
    Object json = mapper.readValue(jsonNode.toString(), Object.class);
    LOG.debug(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));

  }

举个例子

CfnSecurityGroup cfnSecurityGroup = (CfnSecurityGroup) resource_SecurityGroup.getCfnresource();

    if (cfnSecurityGroup.getSecurityGroupIngress() != null) {

      List<Object> cfnSecurityGroupIngress
              = (List<Object>) cfnSecurityGroup.getSecurityGroupIngress();

      ListIterator<Object> it = cfnSecurityGroupIngress.listIterator();

      while (it.hasNext()) {
        Object obj = it.next();
        PrintObjectAsJson(obj);

这将输出以下内容,告诉我们该对象的接口aws cdk类型为cfnsecuritygroup.ingressproperty

{
  "$jsii.byref" : "Object@10016",
  "$jsii.interfaces" : [ "@aws-cdk/aws-ec2.CfnSecurityGroup.IngressProperty" ]
}

相关问题