File tree Expand file tree Collapse file tree
src/main/java/it/aboutbits/springboot/toolbox/jackson Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import it .aboutbits .springboot .toolbox .type .CustomType ;
77
88import java .io .IOException ;
9+ import java .util .UUID ;
910
1011public 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}
You can’t perform that action at this time.
0 commit comments