Skip to content

Commit 7aea196

Browse files
committed
Merge branch '2.x' into 3.x
2 parents d17f1dc + df1c845 commit 7aea196

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

guava/src/main/java/tools/jackson/datatype/guava/deser/GuavaCollectionDeserializer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ public T deserialize(JsonParser p, DeserializationContext ctxt)
134134
return _deserializeContents(p, ctxt);
135135
}
136136
// But may support implicit arrays from single values?
137-
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
137+
final boolean canWrap = (_unwrapSingle == Boolean.TRUE) ||
138+
((_unwrapSingle == null) && ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
139+
if (canWrap) {
138140
return _deserializeFromSingleValue(p, ctxt);
139141
}
142+
// Otherwise, we have a problem
140143
return (T) ctxt.handleUnexpectedToken(getValueType(ctxt), p);
141144
}
142145

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package tools.jackson.datatype.guava;
2+
3+
import java.util.List;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.google.common.collect.ImmutableList;
8+
9+
import com.fasterxml.jackson.annotation.JsonFormat;
10+
11+
import tools.jackson.databind.ObjectMapper;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
15+
// [datatype-guava#185] : `GuavaCollectionDeserializer` does not respect
16+
// `JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY`
17+
public class ImmutableListAcceptSingle185Test
18+
extends ModuleTestBase
19+
{
20+
static class Line {
21+
public String data;
22+
}
23+
24+
static class GuavaContainer185 {
25+
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
26+
public ImmutableList<Line> lines;
27+
}
28+
29+
static class JavaContainer185 {
30+
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
31+
public List<Line> lines;
32+
}
33+
34+
private final ObjectMapper MAPPER = mapperWithModule();
35+
36+
// Sanity Check, JDK List works by default
37+
@Test
38+
public void testJDKListWithSingleValue()
39+
throws Exception
40+
{
41+
String json = "{\"lines\":{\"data\":\"something-jdk\"}}";
42+
43+
JavaContainer185 javaContainer = MAPPER.readValue(json, JavaContainer185.class);
44+
assertEquals(1, javaContainer.lines.size());
45+
assertEquals("something-jdk", javaContainer.lines.get(0).data);
46+
}
47+
48+
// Guava's ImmutableList does not work, but should
49+
@Test
50+
public void testGuavaImmutableListWithSingleValue()
51+
throws Exception
52+
{
53+
String json = "{\"lines\":{\"data\":\"something-guava\"}}";
54+
55+
GuavaContainer185 container = MAPPER.readValue(json, GuavaContainer185.class);
56+
assertEquals(1, container.lines.size());
57+
assertEquals("something-guava", container.lines.get(0).data);
58+
}
59+
}

release-notes/CREDITS-2.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ Joo Hyuk Kim (JooHyukKim@github)
109109
* Contributed fix for #117: (guava) `ImmutableRangeSet` fails to deserialize
110110
without explicit deserializer
111111
(2.16.0)
112+
* Contributed fix for #185: `ACCEPT_SINGLE_VALUE_AS_ARRAY` doesn't work on Guava `ImmutableList`
113+
(2.18.5)
112114

113115
Ethan McCue (@bowbahdoe)
114116
* Reported #122: PCollections module info (`module-info.class`) incorrect
@@ -134,6 +136,10 @@ Arthur Chan (@arthurscchan)
134136
some circumstances
135137
(2.17.0)
136138

139+
Gergely Juhasz (@JGergely)
140+
* Reported #185: `ACCEPT_SINGLE_VALUE_AS_ARRAY` doesn't work on Guava `ImmutableList`
141+
(2.18.5)
142+
137143
Abhishek Kumar (@Abhishekkr3003)
138144
* Contributed #1: (guava) Add deserialization support for `Table<R, C, V>`
139145
(2.19.0)

release-notes/VERSION-2.x

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,25 @@ Active Maintainers:
2121
#190: Add unit tests to verify goodness of SPI metadata for Modules
2222
- Generate SBOMs [JSTEP-14]
2323

24+
2.19.1 (not yet released)
25+
26+
#185: `ACCEPT_SINGLE_VALUE_AS_ARRAY` doesn't work on Guava `ImmutableList`
27+
(reported by Gergely J)
28+
(fix contributed by Joo-Hyuk K)
29+
2430
2.19.0 (24-Apr-2025)
2531
2632
#1: (guava) Add deserialization support for `Table<R, C, V>`
2733
(contributed by Abhishek K)
2834
#174: Unify testing structure/tools [JSTEP-10]
2935
(contributed by Joo-Hyuk K)
3036
37+
2.18.5 (not yet released)
38+
39+
#185: `ACCEPT_SINGLE_VALUE_AS_ARRAY` doesn't work on Guava `ImmutableList`
40+
(reported by Gergely J)
41+
(fix contributed by Joo-Hyuk K)
42+
3143
2.18.4 (06-May-2025)
3244
2.18.3 (28-Feb-2025)
3345
2.18.2 (27-Nov-2024)

0 commit comments

Comments
 (0)