Skip to content

Commit 472c071

Browse files
committed
Add scaffolding for #2815
1 parent 240fcbf commit 472c071

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/std/InetAddressSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public InetAddressSerializer(boolean asNumeric) {
4343
super(InetAddress.class);
4444
_asNumeric = asNumeric;
4545
}
46-
46+
4747
@Override
4848
public JsonSerializer<?> createContextual(SerializerProvider serializers,
4949
BeanProperty property) throws JsonMappingException

src/main/java/com/fasterxml/jackson/databind/ser/std/UUIDSerializer.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import java.io.IOException;
44
import java.util.UUID;
55

6+
import com.fasterxml.jackson.annotation.JsonFormat;
67
import com.fasterxml.jackson.core.JsonGenerator;
78
import com.fasterxml.jackson.databind.*;
89
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
910
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormat;
11+
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
1012
import com.fasterxml.jackson.databind.util.TokenBuffer;
1113

1214
/**
@@ -19,6 +21,7 @@
1921
@SuppressWarnings("serial")
2022
public class UUIDSerializer
2123
extends StdScalarSerializer<UUID>
24+
implements ContextualSerializer // since 2.11.3 (for databind#2815)
2225
{
2326
final static char[] HEX_CHARS = "0123456789abcdef".toCharArray();
2427

@@ -35,6 +38,26 @@ public boolean isEmpty(SerializerProvider prov, UUID value)
3538
return false;
3639
}
3740

41+
@Override
42+
public JsonSerializer<?> createContextual(SerializerProvider serializers,
43+
BeanProperty property) throws JsonMappingException
44+
{
45+
JsonFormat.Value format = findFormatOverrides(serializers,
46+
property, handledType());
47+
Boolean asBinary = null;
48+
if (format != null) {
49+
JsonFormat.Shape shape = format.getShape();
50+
if (shape == JsonFormat.Shape.BINARY) {
51+
asBinary = true;
52+
} else if (shape == JsonFormat.Shape.STRING) {
53+
asBinary = false;
54+
}
55+
// otherwise leave as `null` meaning about same as NATURAL
56+
}
57+
// !!! TODO:
58+
return this;
59+
}
60+
3861
@Override
3962
public void serialize(UUID value, JsonGenerator gen, SerializerProvider provider)
4063
throws IOException
@@ -50,7 +73,7 @@ public void serialize(UUID value, JsonGenerator gen, SerializerProvider provider
5073
return;
5174
}
5275
}
53-
76+
5477
// UUID.toString() works ok functionally, but we can make it go much faster
5578
// (by 4x with micro-benchmark)
5679

@@ -93,7 +116,6 @@ private static void _appendShort(int bits, char[] ch, int offset)
93116
ch[++offset] = HEX_CHARS[(bits >> 8) & 0xF];
94117
ch[++offset] = HEX_CHARS[(bits >> 4) & 0xF];
95118
ch[++offset] = HEX_CHARS[bits & 0xF];
96-
97119
}
98120

99121
private final static byte[] _asBytes(UUID uuid)

0 commit comments

Comments
 (0)