Skip to content

Commit 299fdf5

Browse files
committed
Update release notes wrt #3500, minor cleanup
1 parent bd896b1 commit 299fdf5

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

Diff for: release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,10 @@ PJ Fanning (pjfanning@github)
14801480
* Contributed #3530: Change LRUMap to just evict one entry when maxEntries reached
14811481
(2.14.0)
14821482
1483+
Igor Shymko (ancane@github)
1484+
* Contributed #3500: Add optional explicit `JsonSubTypes` repeated names check
1485+
(2.14.0)
1486+
14831487
Jordi Ortolá Ankum (Tomasito665@github)
14841488
* Contributed #3503: `StdDeserializer` coerces ints to floats even if configured to fail
14851489
(2.14.0)

Diff for: release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Project: jackson-databind
4343
`@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SomeFieldFilter.class)`
4444
(contributed by AmiDavidW@github)
4545
#3497: Deserialization of Throwables with PropertyNamingStrategy does not work
46+
#3500: Add optional explicit `JsonSubTypes` repeated names check
47+
(contributed by Igor S)
4648
#3503: `StdDeserializer` coerces ints to floats even if configured to fail
4749
(contributed by Jordi O-A)
4850
#3528: `TokenBuffer` defaults for parser/stream-read features neither passed

Diff for: src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ public List<NamedType> findSubtypes(Annotated a)
622622
if (t == null) return null;
623623
JsonSubTypes.Type[] types = t.value();
624624

625+
// 02-Aug-2022, tatu: As per [databind#3500], may need to check uniqueness
626+
// of names
625627
if (t.failOnRepeatedNames()) {
626628
return findSubtypesCheckRepeatedNames(a.getName(), types);
627629
} else {
@@ -637,28 +639,28 @@ public List<NamedType> findSubtypes(Annotated a)
637639
}
638640
}
639641

642+
// @since 2.14
640643
private List<NamedType> findSubtypesCheckRepeatedNames(String annotatedTypeName, JsonSubTypes.Type[] types)
641644
{
642645
ArrayList<NamedType> result = new ArrayList<NamedType>(types.length);
643646
Set<String> seenNames = new HashSet<>();
644647
for (JsonSubTypes.Type type : types) {
645-
result.add(new NamedType(type.value(), type.name()));
646-
647-
if (!type.name().isEmpty() && seenNames.contains(type.name())) {
648-
throw new IllegalArgumentException("Annotated type [" + annotatedTypeName + "] got repeated subtype name [" + type.name() + "]");
648+
final String typeName = type.name();
649+
if (!typeName.isEmpty() && seenNames.contains(typeName)) {
650+
throw new IllegalArgumentException("Annotated type [" + annotatedTypeName + "] got repeated subtype name [" + typeName + "]");
649651
} else {
650-
seenNames.add(type.name());
652+
seenNames.add(typeName);
651653
}
654+
result.add(new NamedType(type.value(), typeName));
652655

653656
// [databind#2761]: alternative set of names to use
654-
for (String name : type.names()) {
655-
result.add(new NamedType(type.value(), name));
656-
657-
if (!name.isEmpty() && seenNames.contains(name)) {
658-
throw new IllegalArgumentException("Annotated type [" + annotatedTypeName + "] got repeated subtype name [" + name + "]");
657+
for (String altName : type.names()) {
658+
if (!altName.isEmpty() && seenNames.contains(altName)) {
659+
throw new IllegalArgumentException("Annotated type [" + annotatedTypeName + "] got repeated subtype name [" + altName + "]");
659660
} else {
660-
seenNames.add(name);
661+
seenNames.add(altName);
661662
}
663+
result.add(new NamedType(type.value(), altName));
662664
}
663665
}
664666

0 commit comments

Comments
 (0)