diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java index 3341f9d7ab4..a1a2e9e7cb1 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java @@ -2469,7 +2469,6 @@ private HttpBinding readPayload( + "= __expectObject(await parseBody(output.body, context));"); } else if (target instanceof UnionShape) { // If payload is a Union, then we need to parse the string into JavaScript object. - importUnionDeserializer(writer); writer.write("const data: Record | undefined " + "= await parseBody(output.body, context);"); } else if (target instanceof StringShape || target instanceof DocumentShape) { @@ -2485,6 +2484,7 @@ private HttpBinding readPayload( "if (Object.keys(data ?? {}).length) {", "}", () -> { + importUnionDeserializer(writer); writer.write("contents.$L = __expectUnion($L);", binding.getMemberName(), getOutputValue(context, Location.PAYLOAD, "data", binding.getMember(), target)); }