@Override
    public Void mapShape(MapShape shape) {
        if (nestedLevel == 0) { // Triggered when shape is a member.
            writer.openBlock("$L.expectObjectNode().getMembers().forEach((k, v) -> {",
                    "});",
                    varName,
                    () -> writer.write("builder.putValues($C, $C);",
                            (Runnable) () -> shape.getKey()
                                    .accept(new FromNodeMapperVisitor(writer,
                                            model,
                                            "k")),
                            (Runnable) () -> shape.getValue()
                                    .accept(new FromNodeMapperVisitor(writer,
                                            model,
                                            "v",
                                            nestedLevel + 1))));
        } else { // Triggered when shape is nested.
            String entryName = "entry" + nestedLevel;
            writer.write("$L.expectObjectNode()", varName);
            writer.indent();
            writer.writeWithNoFormatting(".getMembers().entrySet().stream()");
            writer.indent();
            writer.write(".collect($T.toMap(", Collectors.class);
            writer.indent();
            writer.write("$L -> $C, ",
                    entryName,
                    (Runnable) () -> shape.getKey()
                            .accept(new FromNodeMapperVisitor(writer,
                                    model,
                                    entryName + ".getKey()")));
            writer.write("$L -> $C",
                    entryName,
                    (Runnable) () -> shape.getValue()
                            .accept(new FromNodeMapperVisitor(writer,
                                    model,
                                    entryName + ".getValue()",
                                    nestedLevel + 1)));
            writer.dedent();
            writer.write("))");
        }
        return null;
    }
Determines how to map a node to a shape.
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java