Fix queriedMethods handling in ReflectionHintsSerializer
Closes gh-28212
This commit is contained in:
@@ -98,11 +98,9 @@ class ReflectionHintsSerializer {
|
|||||||
if (methodIterator.hasNext()) {
|
if (methodIterator.hasNext()) {
|
||||||
builder.append(",\n");
|
builder.append(",\n");
|
||||||
serializeMethods("methods", methodIterator, builder);
|
serializeMethods("methods", methodIterator, builder);
|
||||||
if (queriedMethodIterator.hasNext()) {
|
|
||||||
builder.append(",\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (queriedMethodIterator.hasNext()) {
|
if (queriedMethodIterator.hasNext()) {
|
||||||
|
builder.append(",\n");
|
||||||
serializeMethods("queriedMethods", queriedMethodIterator, builder);
|
serializeMethods("queriedMethods", queriedMethodIterator, builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,76 @@ public class ReflectionHintsSerializerTests {
|
|||||||
]""", hints);
|
]""", hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void queriedMethods() throws JSONException {
|
||||||
|
ReflectionHints hints = new ReflectionHints();
|
||||||
|
hints.registerType(Integer.class, builder -> builder.withMethod("parseInt", List.of(TypeReference.of(String.class)),
|
||||||
|
(b) -> b.withMode(ExecutableMode.INTROSPECT)));
|
||||||
|
|
||||||
|
assertEquals("""
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "java.lang.Integer",
|
||||||
|
"queriedMethods": [
|
||||||
|
{
|
||||||
|
"name": "parseInt",
|
||||||
|
"parameterTypes": ["java.lang.String"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
""", hints);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void methods() throws JSONException {
|
||||||
|
ReflectionHints hints = new ReflectionHints();
|
||||||
|
hints.registerType(Integer.class, builder -> builder.withMethod("parseInt", List.of(TypeReference.of(String.class)),
|
||||||
|
(b) -> b.withMode(ExecutableMode.INVOKE)));
|
||||||
|
|
||||||
|
assertEquals("""
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "java.lang.Integer",
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"name": "parseInt",
|
||||||
|
"parameterTypes": ["java.lang.String"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
""", hints);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void methodAndQueriedMethods() throws JSONException {
|
||||||
|
ReflectionHints hints = new ReflectionHints();
|
||||||
|
hints.registerType(Integer.class, builder -> builder.withMethod("parseInt", List.of(TypeReference.of(String.class)),
|
||||||
|
(b) -> b.withMode(ExecutableMode.INVOKE)));
|
||||||
|
hints.registerType(Integer.class, builder -> builder.withMethod("parseInt", List.of(TypeReference.of(String.class)),
|
||||||
|
(b) -> b.withMode(ExecutableMode.INTROSPECT)));
|
||||||
|
|
||||||
|
assertEquals("""
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "java.lang.Integer",
|
||||||
|
"queriedMethods": [
|
||||||
|
{
|
||||||
|
"name": "parseInt",
|
||||||
|
"parameterTypes": ["java.lang.String"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"name": "parseInt",
|
||||||
|
"parameterTypes": ["java.lang.String"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
""", hints);
|
||||||
|
}
|
||||||
|
|
||||||
private void assertEquals(String expectedString, ReflectionHints hints) throws JSONException {
|
private void assertEquals(String expectedString, ReflectionHints hints) throws JSONException {
|
||||||
JSONAssert.assertEquals(expectedString, serializer.serialize(hints), JSONCompareMode.LENIENT);
|
JSONAssert.assertEquals(expectedString, serializer.serialize(hints), JSONCompareMode.LENIENT);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user