Skip to content

Commit 0fdfced

Browse files
authored
Change error for unknown union serialization (#511)
1 parent 4ec73e9 commit 0fdfced

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

codegen/core/src/it/java/software/amazon/smithy/java/codegen/test/UnionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import software.amazon.smithy.java.codegen.test.model.NestedUnion;
2727
import software.amazon.smithy.java.codegen.test.model.UnionType;
2828
import software.amazon.smithy.java.core.schema.SerializableShape;
29-
import software.amazon.smithy.java.core.serde.SerializationException;
3029
import software.amazon.smithy.java.core.serde.ShapeSerializer;
3130
import software.amazon.smithy.java.core.serde.document.Document;
3231
import software.amazon.smithy.model.shapes.ShapeType;
@@ -112,6 +111,6 @@ void unknownUnionDeser() {
112111
@Test
113112
void unknownUnionSerFails() {
114113
var union = UnionType.builder().$unknownMember("foo").build();
115-
assertThrows(SerializationException.class, () -> Document.of(union));
114+
assertThrows(UnsupportedOperationException.class, () -> Document.of(union));
116115
}
117116
}

codegen/core/src/main/java/software/amazon/smithy/java/codegen/generators/UnionGenerator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import software.amazon.smithy.java.core.schema.Schema;
2121
import software.amazon.smithy.java.core.schema.SchemaUtils;
2222
import software.amazon.smithy.java.core.schema.SerializableStruct;
23-
import software.amazon.smithy.java.core.serde.SerializationException;
2423
import software.amazon.smithy.java.core.serde.ShapeSerializer;
2524
import software.amazon.smithy.java.core.serde.document.Document;
2625
import software.amazon.smithy.model.Model;
@@ -217,7 +216,7 @@ public static final class $$UnknownMember extends ${shape:T} {
217216
218217
@Override
219218
public void serialize(${shapeSerializer:T} serializer) {
220-
throw new ${serdeException:T}("Cannot serialize union with unknown member " + this.memberName);
219+
throw new ${unsupportedOperation:T}("Cannot serialize union with unknown member " + this.memberName);
221220
}
222221
223222
@Override
@@ -230,7 +229,7 @@ public <T> T getValue() {
230229
}
231230
}
232231
""";
233-
writer.putContext("serdeException", SerializationException.class);
232+
writer.putContext("unsupportedOperation", UnsupportedOperationException.class);
234233
writer.putContext("string", String.class);
235234
writer.write(template);
236235
writer.popState();

0 commit comments

Comments
 (0)