Skip to content

Commit 3fc8025

Browse files
committed
fix the Jackson serializer for CustomType<UUID>
1 parent c272133 commit 3fc8025

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeSerializer.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import it.aboutbits.springboot.toolbox.type.CustomType;
77

88
import java.io.IOException;
9+
import java.util.UUID;
910

1011
public class CustomTypeSerializer extends JsonSerializer<CustomType<?>> {
1112
@SuppressWarnings("unchecked")
@@ -22,17 +23,11 @@ public void serialize(
2223
) throws IOException {
2324
var value = customType.value();
2425

25-
if (value instanceof String stringValue) {
26-
jsonGenerator.writeString(
27-
stringValue
28-
);
29-
return;
26+
switch (value) {
27+
case String stringValue -> jsonGenerator.writeString(stringValue);
28+
case UUID uuidValue -> jsonGenerator.writeString(uuidValue.toString());
29+
case null -> jsonGenerator.writeNull();
30+
default -> jsonGenerator.writeRawValue(String.valueOf(value));
3031
}
31-
32-
jsonGenerator.writeRawValue(
33-
String.valueOf(
34-
value
35-
)
36-
);
3732
}
3833
}

0 commit comments

Comments
 (0)