Fix queriedMethods handling in ReflectionHintsSerializer
Closes gh-28212
This commit is contained in:
parent
d11389e783
commit
1ffc96be8c
|
|
@ -98,11 +98,9 @@ class ReflectionHintsSerializer {
|
|||
if (methodIterator.hasNext()) {
|
||||
builder.append(",\n");
|
||||
serializeMethods("methods", methodIterator, builder);
|
||||
if (queriedMethodIterator.hasNext()) {
|
||||
builder.append(",\n");
|
||||
}
|
||||
}
|
||||
if (queriedMethodIterator.hasNext()) {
|
||||
builder.append(",\n");
|
||||
serializeMethods("queriedMethods", queriedMethodIterator, builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,76 @@ public class ReflectionHintsSerializerTests {
|
|||
]""", 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 {
|
||||
JSONAssert.assertEquals(expectedString, serializer.serialize(hints), JSONCompareMode.LENIENT);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue