Skip to content

Commit df1c845

Browse files
committed
Merge branch '2.19' into 2.x
2 parents 4a40e87 + cc2c2e0 commit df1c845

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaCollectionDeserializer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ public T deserialize(JsonParser p, DeserializationContext ctxt)
138138
return _deserializeContents(p, ctxt);
139139
}
140140
// But may support implicit arrays from single values?
141-
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
141+
final boolean canWrap = (_unwrapSingle == Boolean.TRUE) ||
142+
((_unwrapSingle == null) && ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
143+
if (canWrap) {
142144
return _deserializeFromSingleValue(p, ctxt);
143145
}
146+
// Otherwise, we have a problem
144147
return (T) ctxt.handleUnexpectedToken(_valueClass, p);
145148
}
146149

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

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)