Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
14be345
Backport #3275 in 2.12 (proposing micro-release 2.12.7.2) (#4509)
millems May 2, 2024
b86db52
Prepare for 2.12.7.2 release
cowtowncoder May 2, 2024
2e1b6f2
[maven-release-plugin] prepare release jackson-databind-2.12.7.2
cowtowncoder May 2, 2024
f421d1a
[maven-release-plugin] prepare for next development iteration
cowtowncoder May 2, 2024
24a86c0
Merge branch '2.12' into 2.13
cowtowncoder May 2, 2024
6fb591c
Automatically detect class to deserialize #5064
rohanlopes20 Apr 4, 2025
d885656
Automatically detect class to deserialize #5064
rohanlopes20 Apr 6, 2025
013b19a
Automatically detect class to deserialize #5064
rohanlopes20 Apr 6, 2025
31bfb13
Fixing records deserialization issue (#5094, parts of #4628) with rea…
iifawzi Apr 6, 2025
63b50bb
Merge branch '2.18' into 2.19
cowtowncoder Apr 6, 2025
e89d096
Fix a minor Github CI issue
cowtowncoder Apr 6, 2025
9da0c35
Automatically detect class to deserialize #5064
rohanlopes20 Apr 7, 2025
08251b9
Fixes #5063: generate distinct names (type ids) if `Version` has no a…
cowtowncoder Apr 7, 2025
470f4e9
Fix one bug introduced by #5063 fix
cowtowncoder Apr 7, 2025
1af5bed
Minor javadoc improvement wrt #5063
cowtowncoder Apr 7, 2025
c68e30e
Minor addition to #4628 test
cowtowncoder Apr 7, 2025
7e7b6f7
Prep for 2.19.0-rc1
cowtowncoder Apr 8, 2025
6337820
Prep for 2.19.0-rc1 release
cowtowncoder Apr 8, 2025
70eb5e7
Prep for 2.19.0-rc2 (after botched rc1)
cowtowncoder Apr 8, 2025
6a585de
Disable jacoco, fails on release
cowtowncoder Apr 8, 2025
b6ff25b
[maven-release-plugin] prepare release jackson-databind-2.19.0-rc2
cowtowncoder Apr 8, 2025
8276a5b
[maven-release-plugin] prepare for next development iteration
cowtowncoder Apr 8, 2025
5c215b1
Back to snapshot dep
cowtowncoder Apr 8, 2025
2e169c6
Add cascading rebuild v2 for Hibernate module
cowtowncoder Apr 8, 2025
759b89e
Reduce wait b/w cascading trigger rebuilds
cowtowncoder Apr 8, 2025
8caf21b
Start "master"->"3.x" rename (JSTEP-12)
cowtowncoder Apr 8, 2025
dcd5ec0
Try simplifying branch matches
cowtowncoder Apr 8, 2025
a826991
Fixes #3343: make `BeanPropertyWriter.get()` non-final (#5082)
cowtowncoder Apr 9, 2025
e33c764
Post-merge #3343 fix to Javadoc
cowtowncoder Apr 9, 2025
15d0309
Fixing records deserialization issue when JsonIgnore is used with sam…
iifawzi Apr 11, 2025
b7ac1f0
Merge branch '2.18' into 2.19
cowtowncoder Apr 11, 2025
73dc9e5
Review comments fixes. Removed Test cases of removed code. #5064
rohanlopes20 Apr 12, 2025
f018ed4
Review comments fixes. Removed Test cases of removed code. #5064
rohanlopes20 Apr 12, 2025
3824b11
Update CI to latest Ubuntu
cowtowncoder Apr 17, 2025
aac13a2
Merge branch '2.18' into 2.19
cowtowncoder Apr 17, 2025
3ff375f
modify ObjectReader._parserFactory comment (#5097)
songsunkook Apr 17, 2025
21a11f4
Fix regression in `ObjectNode.with()` (#5099)
rschmitt Apr 22, 2025
707c3c1
Fix #4533, add `MapperFeature.REQUIRE_HANDLERS_FOR_JAVA8_TIMES` (#5105)
JooHyukKim Apr 24, 2025
eb43405
Prep for 2.19.0
cowtowncoder Apr 24, 2025
f644a92
[maven-release-plugin] prepare release jackson-databind-2.19.0
cowtowncoder Apr 24, 2025
a84f99a
[maven-release-plugin] prepare for next development iteration
cowtowncoder Apr 24, 2025
1928b88
Back to snapshot dep
cowtowncoder Apr 24, 2025
119e7cd
Minor javadoc fixes
cowtowncoder Apr 28, 2025
4924007
Merge parts of #5140 first for easier code review of functional chang…
cowtowncoder May 3, 2025
08e6e13
Fixed problem in `CollectionDeserializer` where `_nullProvider` was n…
k163377 May 3, 2025
c0afd56
Remove branch limits from main CI workflow (since wildcards don't work)
cowtowncoder May 3, 2025
7922847
Merge branch '2.18' into 2.19
cowtowncoder May 3, 2025
75dc91f
Prep for 2.18.4
cowtowncoder May 7, 2025
4b66d3f
[maven-release-plugin] prepare release jackson-databind-2.18.4
cowtowncoder May 7, 2025
f3b2c44
[maven-release-plugin] prepare for next development iteration
cowtowncoder May 7, 2025
8065c4f
back to snapshot dep
cowtowncoder May 7, 2025
a7f73ca
Merge branch '2.18' into 2.19
cowtowncoder May 7, 2025
05f2ff4
Try fixing CI branch matching
cowtowncoder May 7, 2025
07c9cb2
Merge branch '2.18' into 2.19
cowtowncoder May 7, 2025
de41882
Add failing test for #4656 (#5147)
cowtowncoder May 8, 2025
6f32617
Minor javadoc add
cowtowncoder May 15, 2025
46f0168
Minor pom fix
cowtowncoder May 27, 2025
de7155b
Fix CI snapshot publishing
cowtowncoder May 27, 2025
000243a
Switch snapshot access to central portal
cowtowncoder May 27, 2025
c33e331
Merge branch '2.18' into 2.19
cowtowncoder May 27, 2025
686b5dc
Manual merge of pom.xml
cowtowncoder May 27, 2025
97eead5
Add test against #5115 (#5183)
JooHyukKim Jun 10, 2025
272ef12
JDK 22 -> 23 in CI
cowtowncoder Jun 10, 2025
30e4b7f
Add test for #5184 (#5185)
JooHyukKim Jun 10, 2025
05eb538
Merge branch '2.18' into 2.19
cowtowncoder Jun 10, 2025
8242174
Remove JDK 23 from 2.18 CI due to Mockito incompatibility
cowtowncoder Jun 10, 2025
614d341
Merge branch '2.18' into 2.19
cowtowncoder Jun 10, 2025
eb302c9
Prep for 2.19.1
cowtowncoder Jun 14, 2025
cb317b0
[maven-release-plugin] prepare release jackson-databind-2.19.1
cowtowncoder Jun 14, 2025
cdcb0b1
[maven-release-plugin] prepare for next development iteration
cowtowncoder Jun 14, 2025
b8f8c54
back to snapshot dep
cowtowncoder Jun 14, 2025
7cc79d3
Refactor for MapDeserializer and EnumMapDeserializer (#5189)
k163377 Jun 14, 2025
29d498a
Refactor for ObjectArrayDeserializer, StringArrayDeserializer, String…
k163377 Jun 16, 2025
b29d3ab
Fix #5165 on MapDeserializer and EnumMapDeserializer (#5191)
k163377 Jun 16, 2025
ea940e5
Fix serialization order change after #4775 (`@JsonAnyGetter` respects…
JooHyukKim Jul 9, 2025
dd27a21
Update release notes wrt #5215
cowtowncoder Jul 9, 2025
1464997
`JsonSetter.contentNulls` ignored for `Object[]`, `String[]` and `Col…
k163377 Jul 9, 2025
aaaceb8
Trigger CI for 2.19
cowtowncoder Jul 11, 2025
bcb78ac
Prep for 2.19.2
cowtowncoder Jul 18, 2025
1a50604
[maven-release-plugin] prepare release jackson-databind-2.19.2
cowtowncoder Jul 18, 2025
fe5a013
[maven-release-plugin] prepare for next development iteration
cowtowncoder Jul 18, 2025
4439898
Back to snapshot dep
cowtowncoder Jul 18, 2025
6babf5c
Backport junit5 fix from 2.x to 2.19
cowtowncoder Aug 1, 2025
9279965
Add NPE handling wrt DeserializationContext.getParser() (#5245)
cowtowncoder Aug 5, 2025
d90d157
Javadoc improvements wrt #5211
cowtowncoder Aug 5, 2025
4bb1b51
Merge branch '2.18' into 2.19
cowtowncoder Aug 5, 2025
4963374
Javadoc improvements wrt #5211
cowtowncoder Aug 5, 2025
9545bdd
Merge branch '2.18' into 2.19
cowtowncoder Aug 5, 2025
cc54617
3 javadoc fixes
cowtowncoder Aug 5, 2025
4c0f8a7
Merge branch '2.18' into 2.19
cowtowncoder Aug 5, 2025
09b82dc
Fix parts of 2.16 CI (#5278)
cowtowncoder Aug 25, 2025
221dd3c
Merge branch '2.16' into 2.17
cowtowncoder Aug 25, 2025
ef7c303
Merge branch '2.17' into 2.18
cowtowncoder Aug 25, 2025
449509b
Backport #5280
cowtowncoder Aug 26, 2025
cac9745
Merge branch '2.16' into 2.17
cowtowncoder Aug 26, 2025
f1a80bf
Manual backport of #5280
cowtowncoder Aug 26, 2025
ada97f5
Merge branch '2.17' into 2.18
cowtowncoder Aug 26, 2025
814ce08
Manual backport of #5280
cowtowncoder Aug 26, 2025
cd1fa61
Merge branch '2.18' into 2.19
cowtowncoder Aug 26, 2025
6980e2e
Manual backport of #5280
cowtowncoder Aug 26, 2025
ee9240c
Minor test improvement
cowtowncoder Aug 27, 2025
acb1fc4
Merge branch '2.18' into 2.19
cowtowncoder Aug 27, 2025
8840115
Add more documentation (#5284)
JooHyukKim Aug 31, 2025
08d4a39
Merge branch '2.18' into 2.19
cowtowncoder Aug 31, 2025
1595f0b
Update release notes wrt #3328 / [CVE-2021-46877] link
cowtowncoder Sep 2, 2025
72f1478
Merge branch '2.12' into 2.13
cowtowncoder Sep 2, 2025
d8bcbba
Merge branch '2.13' into 2.14
cowtowncoder Sep 2, 2025
145397d
Merge branch '2.14' into 2.15
cowtowncoder Sep 2, 2025
5330e4f
Merge branch '2.15' into 2.16
cowtowncoder Sep 2, 2025
bcccddf
Merge branch '2.16' into 2.17
cowtowncoder Sep 2, 2025
57982e7
Merge branch '2.17' into 2.18
cowtowncoder Sep 2, 2025
3cca4bb
Merge branch '2.18' into 2.19
cowtowncoder Sep 2, 2025
7ea3372
Reproduce 5281 (#5286)
JooHyukKim Sep 3, 2025
653dcf5
Merge branch '2.18' into 2.19
cowtowncoder Sep 3, 2025
dfaf90b
Merge branch 'FasterXML:2.19' into 2.19
rohanlopes20 Sep 9, 2025
184e383
Renamed method to readObject for 3.x
rohanlopes20 Sep 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3055,6 +3055,23 @@ public <T> T readValue(JsonParser p, Class<T> valueType)
return (T) _readValue(getDeserializationConfig(), p, _typeFactory.constructType(valueType));
}

/**
* Reads the value from the given JSON content and automatically detects the class type.
*
* @param <T> the type of the object to read
* @param p the JsonParser
* @param reified don't pass any values here. It's a trick to detect the class type.
* @return the deserialized object
* @throws JsonProcessingException if there is a problem processing the JSON
*/
public <T> T readValue(JsonParser p, T... reified) throws IOException {
if (reified.length > 0) {
throw new IllegalArgumentException("Please don't pass any values here. Java will detect class automatically.");
}

return readValue(p, _typeFactory.constructType(getClassOf(reified)));
}

/**
* Method to deserialize JSON content into a Java type, reference
* to which is passed as argument. Type is passed using so-called
Expand Down Expand Up @@ -3855,6 +3872,34 @@ public <T> T readValue(String content, Class<T> valueType)
return readValue(content, _typeFactory.constructType(valueType));
}

/**
* Utility method to get the class type from a varargs array.
*
* @param <T> the generic type
* @param array the varargs array
* @return the class of the array component
*/
private static <T> Class<T> getClassOf(T[] array) {
return (Class<T>) array.getClass().getComponentType();
}

/**
* Reads the value from the given JSON content and automatically detects the class type.
*
* @param <T> the type of the object to read
* @param content the JSON string
* @param reified don't pass any values here. It's a trick to detect the class type.
* @return the deserialized object
* @throws JsonProcessingException if there is a problem processing the JSON
*/
public <T> T readValue(String content, T... reified) throws JsonProcessingException {
if (reified.length > 0) {
throw new IllegalArgumentException("Please don't pass any values here. Java will detect class automatically.");
}

return readValue(content, _typeFactory.constructType(getClassOf(reified)));
}

/**
* Method to deserialize JSON content from given JSON content String.
*
Expand Down Expand Up @@ -3957,6 +4002,15 @@ public <T> T readValue(byte[] src, int offset, int len,
return (T) _readMapAndClose(_jsonFactory.createParser(src, offset, len), _typeFactory.constructType(valueType));
}

@SuppressWarnings("unchecked")
public <T> T readValue(byte[] src, int offset, int len, T... reified) throws IOException {
if (reified.length > 0) {
throw new IllegalArgumentException("Please don't pass any values here. Java will detect class automatically.");
}

return readValue(src, offset, len, _typeFactory.constructType(getClassOf(reified)));
}

@SuppressWarnings({ "unchecked" })
public <T> T readValue(byte[] src, TypeReference<T> valueTypeRef)
throws IOException, StreamReadException, DatabindException
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/com/fasterxml/jackson/databind/ObjectReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ public void writeTree(JsonGenerator g, TreeNode rootNode) {
* @param src Source to read content from
*/
@SuppressWarnings("unchecked")
public <T> T readValue(InputStream src) throws IOException
private <T> T readValue(InputStream src) throws IOException
{
if (_dataFormatReaders != null) {
return (T) _detectBindAndClose(_dataFormatReaders.findFormat(src), false);
Expand All @@ -1515,6 +1515,12 @@ public <T> T readValue(InputStream src, Class<T> valueType) throws IOException
return (T) forType(valueType).readValue(src);
}

@SuppressWarnings("unchecked")
public <T> T readValue(InputStream src, T... reified) throws IOException
{
return forType(getClassOf(reified)).readValue(src);
}

/**
* Method that binds content read from given input source,
* using configuration of this reader.
Expand Down Expand Up @@ -1585,6 +1591,26 @@ public <T> T readValue(String src, Class<T> valueType) throws IOException
return (T) forType(valueType).readValue(src);
}

@SuppressWarnings("unchecked")
public <T> T readValue(String src, T... reified) throws IOException {
if (reified.length > 0) {
throw new IllegalArgumentException("Please don't pass any values here. Java will detect class automatically.");
}

return readValue(src, getClassOf(reified));
}

/**
* Utility method to get the class type from a varargs array.
*
* @param <T> the generic type
* @param array the varargs array
* @return the class of the array component
*/
private static <T> Class<T> getClassOf(T[] array) {
return (Class<T>) array.getClass().getComponentType();
}

/**
* Method that binds content read from given byte array,
* using configuration of this reader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public void testBoundsWithByteArrayInput() throws Exception {
final JavaType TYPE = MAPPER.constructType(String.class);
_testBoundsWithByteArrayInput(
(data,offset,len)->MAPPER.readValue(data, offset, len, TYPE));

_testBoundsWithByteArrayInput(
(data,offset,len)->MAPPER.readValue(data, offset, len));
}

private void _testBoundsWithByteArrayInput(ByteBackedCreation creator) throws Exception
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,16 @@ public void testJsonFactoryLinkage()
assertSame(m, f.getCodec());
}

@Test
public void testAutoDetectClasses() throws Exception
{
ObjectMapper m = new ObjectMapper();
final String JSON = "{ \"x\" : 3 }";

Bean bean = m.readValue(JSON);
assertNotNull(bean);
}

@Test
public void testProviderConfig() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ public void testCanPassResultToOverloadedMethod() throws Exception {
ObjectReader reader = MAPPER.readerFor(POJO.class).at("/foo/bar/caller");

process(reader.readValue(source, POJO.class));

POJO pojo = reader.readValue(source);
process(pojo);
}

void process(POJO pojo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,50 @@ public void testTokenBufferWithSample() throws Exception
}
}

@Test
public void testTokenBufferWithSequenceWithAutoDetectClass() throws Exception
{
final ObjectMapper mapper = jsonMapperBuilder()
.disable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
.build();

// and then sequence of other things
JsonParser p = mapper.createParser("[ 32, [ 1 ], \"abc\", { \"a\" : true } ]");
assertToken(JsonToken.START_ARRAY, p.nextToken());

assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
TokenBuffer buf = mapper.readValue(p);

// check manually...
JsonParser bufParser = buf.asParser();
assertToken(JsonToken.VALUE_NUMBER_INT, bufParser.nextToken());
assertEquals(32, bufParser.getIntValue());
assertNull(bufParser.nextToken());

// then bind to another
buf = mapper.readValue(p);
bufParser = buf.asParser();
assertToken(JsonToken.START_ARRAY, bufParser.nextToken());
assertToken(JsonToken.VALUE_NUMBER_INT, bufParser.nextToken());
assertEquals(1, bufParser.getIntValue());
assertToken(JsonToken.END_ARRAY, bufParser.nextToken());
assertNull(bufParser.nextToken());

// third one, with automatic binding
buf = mapper.readValue(p);
String str = mapper.readValue(buf.asParser());
assertEquals("abc", str);

// and ditto for last one
buf = mapper.readValue(p, TokenBuffer.class);
Map<?,?> map = mapper.readValue(buf.asParser());
assertEquals(1, map.size());
assertEquals(Boolean.TRUE, map.get("a"));

assertEquals(JsonToken.END_ARRAY, p.nextToken());
assertNull(p.nextToken());
}

@SuppressWarnings("resource")
@Test
public void testTokenBufferWithSequence() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ public void testLocaleFuzz47034() throws Exception
assertNotNull(loc);
}

@Test
public void testLocaleFuzz47034WithAutoDetectClss() throws Exception
{
Locale loc = MAPPER.reader()
.without(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
.readValue(getClass().getResourceAsStream("/fuzz/oss-fuzz-47034.json"));
assertNotNull(loc);
}

// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47036
// @since 2.14
@Test
Expand Down