Skip to content

(WIP) Reflection testing on 2.x wrt #4907 #5119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ffd7ef8
Check in skeletal test
cowtowncoder Apr 26, 2025
46215ba
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder Apr 26, 2025
a1ab4a9
...
cowtowncoder Apr 26, 2025
0ad4bc4
More debug printing
cowtowncoder Apr 27, 2025
ac67f6c
...
cowtowncoder Apr 28, 2025
58c7ebc
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 2, 2025
bc2edfc
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 2, 2025
a3c0e27
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 2, 2025
6af8451
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 2, 2025
ff301c6
Merge branch 'tatu/2.20/4907-graal-introspection' of github.com:Faste…
cowtowncoder May 2, 2025
9355c96
...
cowtowncoder May 2, 2025
e9c0964
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 3, 2025
731ad8f
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 3, 2025
835590f
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 7, 2025
f18eb2c
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 8, 2025
9956070
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 13, 2025
aceef7b
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 18, 2025
c7b3fad
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 20, 2025
9261de5
Merge branch '2.x' into tatu/2.20/4907-graal-introspection
cowtowncoder May 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public final class AnnotatedClass
*/
protected final boolean _collectAnnotations;

/**
* Flag that indicates whether member (Field, Method, Constructor}
* detection should occur: starting with 2.19 is disabled for <b>core</b> JDK
* types {@link ClassUtil#isJDKCoreClass(Class)}).
*
* @since 2.20
*/
protected final boolean _collectMembers;

/*
/**********************************************************
/* Gathered information
Expand Down Expand Up @@ -151,6 +160,19 @@ public final class AnnotatedClass
_mixInResolver = mir;
_typeFactory = tf;
_collectAnnotations = collectAnnotations;
// But need to collect for some JDK types:
//
// - Throwables
_collectMembers = (type != null)
&& (!ClassUtil.isJDKCoreClass(rawType)
|| type.hasRawClass(Optional.class)
|| type.hasRawClass(StackTraceElement.class)
|| Throwable.class.isAssignableFrom(rawType)
|| type.hasRawClass(Thread.class)
|| type.hasRawClass(ThreadGroup.class)
);

System.out.println(" AnnotatedClass("+_type+"), coll anno? "+collectAnnotations+" coll mem? "+_collectMembers);
}

/**
Expand All @@ -170,6 +192,7 @@ public final class AnnotatedClass
_mixInResolver = null;
_typeFactory = null;
_collectAnnotations = false;
_collectMembers = false;
}

/*
Expand Down Expand Up @@ -308,9 +331,12 @@ private final List<AnnotatedField> _fields() {
List<AnnotatedField> f = _fields;
if (f == null) {
// 09-Jun-2017, tatu: _type only null for primordial, placeholder array types.
if (_type == null) {
// 26-Apr-2025, tatu: [databind#4907] Less introspection, skip for core JDK types
if (_type == null || !_collectMembers) {
System.out.println("SKIP Collecting _fields() for "+_type);
f = Collections.emptyList();
} else {
System.out.println("Collecting _fields() for "+_type);
f = AnnotatedFieldCollector.collectFields(_annotationIntrospector,
this, _mixInResolver, _typeFactory, _type, _collectAnnotations);
}
Expand All @@ -324,9 +350,11 @@ private final AnnotatedMethodMap _methods() {
if (m == null) {
// 09-Jun-2017, tatu: _type only null for primordial, placeholder array types.
// NOTE: would be great to have light-weight shareable maps; no such impl exists for now
if (_type == null) {
if (_type == null) { // || !_collectMembers) {
System.out.println("SKIP Collecting _methods() for: "+_type);
m = new AnnotatedMethodMap();
} else {
System.out.println("Collecting _methods() for "+_type);
m = AnnotatedMethodCollector.collectMethods(_annotationIntrospector,
this,
_mixInResolver, _typeFactory,
Expand All @@ -340,9 +368,12 @@ private final AnnotatedMethodMap _methods() {
private final Creators _creators() {
Creators c = _creators;
if (c == null) {
if (_type == null) {
// 26-Apr-2025, tatu: [databind#4907] Less introspection, skip for core JDK types
if (_type == null || !_collectMembers) {
System.out.println("SKIP Collecting _creators() for: "+_type);
c = NO_CREATORS;
} else {
System.out.println("Collecting _creators() for "+_type);
c = AnnotatedCreatorCollector.collectCreators(_annotationIntrospector,
_typeFactory,
this, _type, _primaryMixIn, _collectAnnotations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ static AnnotatedClass createArrayType(MapperConfig<?> config, Class<?> raw) {
}

AnnotatedClass resolveFully() {
System.out.println(" AnnotatedClassResolver.resolveFully() for "+_type);

List<JavaType> superTypes = new ArrayList<>(8);
if (!_type.hasRawClass(Object.class)) {
if (_type.isInterface()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public BasicBeanDescription forSerialization(SerializationConfig config,
// structured types as well
desc = _findStdJdkCollectionDesc(config, type);
if (desc == null) {
System.out.println("BasicBeanDescription.forSerialization() for "+type);
desc = BasicBeanDescription.forSerialization(collectProperties(config,
type, r, true));
}
Expand All @@ -101,6 +102,7 @@ public BasicBeanDescription forDeserialization(DeserializationConfig config,
// structured types as well
desc = _findStdJdkCollectionDesc(config, type);
if (desc == null) {
System.out.println("BasicBeanDescription.forDeserialization() for "+type);
desc = BasicBeanDescription.forDeserialization(collectProperties(config,
type, r, false));
}
Expand All @@ -127,6 +129,7 @@ public BasicBeanDescription forCreation(DeserializationConfig config,
// structured types as well
desc = _findStdJdkCollectionDesc(config, type);
if (desc == null) {
System.out.println("BasicBeanDescription.forCreation() for "+type);
desc = BasicBeanDescription.forDeserialization(
collectProperties(config, type, r, false));
}
Expand Down Expand Up @@ -170,6 +173,7 @@ public BasicBeanDescription forDirectClassAnnotations(MapperConfig<?> config,
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config,
JavaType type, MixInResolver r, boolean forSerialization)
{
System.out.println(" collectProperties() for "+type);
final AnnotatedClass classDef = _resolveAnnotatedClass(config, type, r);
final AccessorNamingStrategy accNaming = type.isRecordType()
? config.getAccessorNaming().forRecord(config, classDef)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.fasterxml.jackson.databind.misc;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class Reflection4907Test extends DatabindTestUtil
{
static class SqlDatePojo {
public String name;
public java.sql.Date date;

public SqlDatePojo() {
}

public SqlDatePojo(String name, java.sql.Date date) {
this.name = name;
this.date = date;
}

public SqlDatePojo(java.sql.Date date) {
this.date = date;
}

public java.sql.Date getDate() {
return date;
}

public void setDate(java.sql.Date date) {
this.date = date;
}
}

private final ObjectMapper MAPPER = newJsonMapper();

// [databind#4907]
@Test
public void test4907Read() throws Exception {
System.err.println("<testRead>");
SqlDatePojo pojo = MAPPER.readValue(a2q("{'date':'2000-01-01', 'name':'foo'}"),
SqlDatePojo.class);
System.err.println("</testRead>");
assertNotNull(pojo);
}

// [databind#4907]
@Test
public void test4907Write() throws Exception {
System.err.println("<testWrite>");
String json = MAPPER.writeValueAsString(new SqlDatePojo("foobar",
java.sql.Date.valueOf("2000-01-01")));
System.err.println("</testWrite>");
assertNotNull(json);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ public void testNonStandardProperties() throws Exception
public void testThreadSerialization() throws Exception
{
final Thread input = Thread.currentThread();
// String json = MAPPER.writerWithDefaultPrettyPrinter()
// .writeValueAsString(input);
// System.err.println("Thread -> "+MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(input));

Map<?,?> asMap = MAPPER.convertValue(input, Map.class);
// System.err.println("PROPS -> "+asMap.keySet());

Expand Down
Loading