@Test public void omitsDefaultsFromSerializedNode() { TraitFactory provider = TraitFactory.createServiceFactory(); ObjectNode node = Node.objectNode() .withMember("origin", Node.from("*")) .withMember("maxAge", Node.from(600)) .withMember("additionalAllowedHeaders", Node.fromStrings()) .withMember("additionalExposedHeaders", Node.fromStrings()); Optional<Trait> trait = provider.createTrait(ShapeId.from("smithy.api#cors"), ShapeId.from("ns.qux#foo"), node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(CorsTrait.class)); ObjectNode serialized = ((CorsTrait) trait.get()).createNode().expectObjectNode(); assertFalse(serialized.getMember("origin").isPresent()); assertFalse(serialized.getMember("maxAge").isPresent()); assertFalse(serialized.getMember("additionalAllowedHeaders").isPresent()); assertFalse(serialized.getMember("additionalExposedHeaders").isPresent()); }
@Override protected Node createNode() { return new ObjectNode(MapUtils.of(), getSourceLocation()) .withOptionalMember(ORIGIN_MEMBER_ID, Optional.of(origin) .filter(val -> !val.equals(DEFAULT_ORIGIN)) .map(Node::from)) .withOptionalMember(MAX_AGE_MEMBER_ID, Optional.of(maxAge) .filter(val -> !val.equals(DEFAULT_MAX_AGE)) .map(Node::from)) .withOptionalMember(ALLOWED_HEADERS_MEMBER_ID, Optional.of(additionalAllowedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)) .withOptionalMember(EXPOSED_HEADERS_MEMBER_ID, Optional.of(additionalExposedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)); }
CorsTrait extends AbstractTrait implements ToSmithyBuilder<CorsTrait> { @Override protected Node createNode() { return new ObjectNode(MapUtils.of(), getSourceLocation()) .withOptionalMember(ORIGIN_MEMBER_ID, Optional.of(origin) .filter(val -> !val.equals(DEFAULT_ORIGIN)) .map(Node::from)) .withOptionalMember(MAX_AGE_MEMBER_ID, Optional.of(maxAge) .filter(val -> !val.equals(DEFAULT_MAX_AGE)) .map(Node::from)) .withOptionalMember(ALLOWED_HEADERS_MEMBER_ID, Optional.of(additionalAllowedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)) .withOptionalMember(EXPOSED_HEADERS_MEMBER_ID, Optional.of(additionalExposedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)); } }
CorsTrait extends AbstractTrait implements ToSmithyBuilder<CorsTrait> { @Override protected Node createNode() { return new ObjectNode(MapUtils.of(), getSourceLocation()) .withOptionalMember(ORIGIN_MEMBER_ID, Optional.of(origin) .filter(val -> !val.equals(DEFAULT_ORIGIN)) .map(Node::from)) .withOptionalMember(MAX_AGE_MEMBER_ID, Optional.of(maxAge) .filter(val -> !val.equals(DEFAULT_MAX_AGE)) .map(Node::from)) .withOptionalMember(ALLOWED_HEADERS_MEMBER_ID, Optional.of(additionalAllowedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)) .withOptionalMember(EXPOSED_HEADERS_MEMBER_ID, Optional.of(additionalExposedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)); } private  CorsTrait(Builder builder); }
CorsTrait extends AbstractTrait implements ToSmithyBuilder<CorsTrait> { @Override protected Node createNode() { return new ObjectNode(MapUtils.of(), getSourceLocation()) .withOptionalMember(ORIGIN_MEMBER_ID, Optional.of(origin) .filter(val -> !val.equals(DEFAULT_ORIGIN)) .map(Node::from)) .withOptionalMember(MAX_AGE_MEMBER_ID, Optional.of(maxAge) .filter(val -> !val.equals(DEFAULT_MAX_AGE)) .map(Node::from)) .withOptionalMember(ALLOWED_HEADERS_MEMBER_ID, Optional.of(additionalAllowedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)) .withOptionalMember(EXPOSED_HEADERS_MEMBER_ID, Optional.of(additionalExposedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)); } private  CorsTrait(Builder builder); String getOrigin(); int getMaxAge(); Set<String> getAdditionalAllowedHeaders(); Set<String> getAdditionalExposedHeaders(); @Override Builder toBuilder(); static Builder builder(); }
CorsTrait extends AbstractTrait implements ToSmithyBuilder<CorsTrait> { @Override protected Node createNode() { return new ObjectNode(MapUtils.of(), getSourceLocation()) .withOptionalMember(ORIGIN_MEMBER_ID, Optional.of(origin) .filter(val -> !val.equals(DEFAULT_ORIGIN)) .map(Node::from)) .withOptionalMember(MAX_AGE_MEMBER_ID, Optional.of(maxAge) .filter(val -> !val.equals(DEFAULT_MAX_AGE)) .map(Node::from)) .withOptionalMember(ALLOWED_HEADERS_MEMBER_ID, Optional.of(additionalAllowedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)) .withOptionalMember(EXPOSED_HEADERS_MEMBER_ID, Optional.of(additionalExposedHeaders) .filter(FunctionalUtils.not(Set::isEmpty)) .map(Node::fromStrings)); } private  CorsTrait(Builder builder); String getOrigin(); int getMaxAge(); Set<String> getAdditionalAllowedHeaders(); Set<String> getAdditionalExposedHeaders(); @Override Builder toBuilder(); static Builder builder(); static final ShapeId ID; }