Skip to content

Commit 5bca846

Browse files
committed
Merge branch '2.12'
2 parents 5e7b693 + d6ba346 commit 5bca846

File tree

3 files changed

+106
-8
lines changed

3 files changed

+106
-8
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/ValueInstantiator.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ public Class<?> getValueClass() {
410410
}
411411
}
412412

413-
414413
/**
415414
* Delegating {@link ValueInstantiator} implementation meant as a base type
416415
* that by default delegates methods to specified fallback instantiator.
@@ -529,7 +528,7 @@ public Object createFromDouble(DeserializationContext ctxt, double value) throws
529528
@Override
530529
public Object createFromBoolean(DeserializationContext ctxt, boolean value) throws IOException {
531530
return delegate().createFromBoolean(ctxt, value);
532-
}
531+
}
533532

534533
/*
535534
/**********************************************************

src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKStringLikeTypesTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,9 @@ public void testURLInvalid() throws Exception
305305

306306
public void testUUID() throws Exception
307307
{
308-
final ObjectMapper mapper = jsonMapperBuilder()
309-
.disable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
310-
.build();
311308
final String NULL_UUID = "00000000-0000-0000-0000-000000000000";
309+
final ObjectReader r = MAPPER.readerFor(UUID.class);
310+
312311
// first, couple of generated UUIDs:
313312
for (String value : new String[] {
314313
"76e6d183-5f68-4afa-b94a-922c1fdb83f8",
@@ -320,7 +319,8 @@ public void testUUID() throws Exception
320319
}) {
321320
UUID uuid = UUID.fromString(value);
322321
assertEquals(uuid,
323-
mapper.readValue(quote(value), UUID.class));
322+
r.without(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
323+
.readValue(quote(value)));
324324
}
325325
// then use templating; note that these are not exactly valid UUIDs
326326
// wrt spec (type bits etc), but JDK UUID should deal ok
@@ -330,13 +330,13 @@ public void testUUID() throws Exception
330330
for (int i = 0; i < chars.length(); ++i) {
331331
String value = TEMPL.replace('0', chars.charAt(i));
332332
assertEquals(UUID.fromString(value).toString(),
333-
mapper.readValue(quote(value), UUID.class).toString());
333+
r.readValue(quote(value)).toString());
334334
}
335335

336336
// also: see if base64 encoding works as expected
337337
String base64 = Base64Variants.getDefaultVariant().encode(new byte[16]);
338338
assertEquals(UUID.fromString(NULL_UUID),
339-
mapper.readValue(quote(base64), UUID.class));
339+
r.readValue(quote(base64)));
340340
}
341341

342342
public void testUUIDInvalid() throws Exception
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.UUID;
4+
5+
import com.fasterxml.jackson.annotation.JsonFormat;
6+
import com.fasterxml.jackson.annotation.OptBoolean;
7+
8+
import com.fasterxml.jackson.databind.BaseMapTest;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
10+
11+
public class JDKStringLikeTypes2066Test extends BaseMapTest
12+
{
13+
static class UUIDWrapper {
14+
public UUID value;
15+
}
16+
17+
static class StrictUUIDWrapper {
18+
@JsonFormat(lenient=OptBoolean.FALSE)
19+
public UUID value;
20+
}
21+
22+
/*
23+
/**********************************************************
24+
/* Test methods
25+
/**********************************************************
26+
*/
27+
28+
// [databind#2066]
29+
public void testUUIDLeniencyDefault() throws Exception
30+
{
31+
final ObjectMapper MAPPER = objectMapper();
32+
33+
// By default, empty String OK
34+
assertNull(MAPPER.readValue(quote(""), UUID.class));
35+
36+
UUIDWrapper w = MAPPER.readValue("{\"value\":\"\"}", UUIDWrapper.class);
37+
assertNull(w.value);
38+
}
39+
40+
// [databind#2066]
41+
public void testUUIDLeniencyGlobal() throws Exception
42+
{
43+
final ObjectMapper STRICT_MAPPER = jsonMapperBuilder()
44+
.defaultLeniency(Boolean.FALSE)
45+
.build();
46+
try {
47+
STRICT_MAPPER.readValue(quote(""), UUID.class);
48+
fail("Should not pass");
49+
} catch (Exception e) {
50+
_verifyBadUUID(e);
51+
}
52+
53+
try {
54+
STRICT_MAPPER.readValue("{\"value\":\"\"}", UUIDWrapper.class);
55+
fail("Should not pass");
56+
} catch (Exception e) {
57+
_verifyBadUUID(e);
58+
}
59+
}
60+
61+
// [databind#2066]
62+
public void testUUIDLeniencyByType() throws Exception
63+
{
64+
final ObjectMapper STRICT_MAPPER = jsonMapperBuilder()
65+
.withConfigOverride(UUID.class,
66+
cfg -> cfg.setFormat(JsonFormat.Value.forLeniency(false)))
67+
.build();
68+
69+
try {
70+
STRICT_MAPPER.readValue(quote(""), UUID.class);
71+
fail("Should not pass");
72+
} catch (Exception e) {
73+
_verifyBadUUID(e);
74+
}
75+
76+
try {
77+
STRICT_MAPPER.readValue("{\"value\":\"\"}", UUIDWrapper.class);
78+
fail("Should not pass");
79+
} catch (Exception e) {
80+
_verifyBadUUID(e);
81+
}
82+
}
83+
84+
// [databind#2066]
85+
public void testUUIDLeniencyByProperty() throws Exception
86+
{
87+
final ObjectMapper MAPPER = objectMapper();
88+
try {
89+
MAPPER.readValue("{\"value\":\"\"}", StrictUUIDWrapper.class);
90+
fail("Should not pass");
91+
} catch (Exception e) {
92+
_verifyBadUUID(e);
93+
}
94+
}
95+
96+
private void _verifyBadUUID(Exception e) {
97+
verifyException(e, "foobar"); // TODO: real exception message we want
98+
}
99+
}

0 commit comments

Comments
 (0)