Skip to content

Commit

Permalink
Test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 8, 2024
1 parent de844c5 commit 279f69c
Showing 1 changed file with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ public String toString() {
}
}

static class DelegatingCanonicalFindingIntrospector extends ImplicitNameIntrospector
static class PrimaryCreatorFindingIntrospector extends ImplicitNameIntrospector
{
private static final long serialVersionUID = 1L;

private final Class<?> _argType;
private final Class<?>[] _argTypes;

public DelegatingCanonicalFindingIntrospector(Class<?> argType) {
_argType = argType;
private JsonCreator.Mode _mode;

public PrimaryCreatorFindingIntrospector(JsonCreator.Mode mode,
Class<?>... argTypes) {
_mode = mode;
_argTypes = argTypes;
}

@Override
Expand All @@ -78,12 +82,20 @@ public PotentialCreator findPrimaryCreator(MapperConfig<?> config,
System.err.println("findCanonicalCreator DONE for: "+valueClass.getRawType());
List<PotentialCreator> combo = new ArrayList<>(declaredConstructors);
combo.addAll(declaredFactories);
final int argCount = _argTypes.length;
for (PotentialCreator ctor : combo) {
if (ctor.paramCount() == 1
&& _argType == ctor.param(0).getRawType()) {
if (ctor.paramCount() == argCount) {
int i = 0;
for (; i < argCount; ++i) {
if (_argTypes[i] != ctor.param(i).getRawType()) {
break;
}
}
if (i == argCount) {
System.err.println("MATCH! "+ctor);
ctor.overrideMode(JsonCreator.Mode.DELEGATING);
return ctor;
ctor.overrideMode(_mode);
return ctor;
}
}
}
System.err.println("No MATCH! ");
Expand All @@ -102,7 +114,8 @@ public PotentialCreator findPrimaryCreator(MapperConfig<?> config,
public void testCanonicalConstructorPropertiesCreator() throws Exception
{
assertEquals(POJO4584.factoryString("List[0]"),
readerWith(new DelegatingCanonicalFindingIntrospector(List.class))
readerWith(new PrimaryCreatorFindingIntrospector(JsonCreator.Mode.PROPERTIES,
List.class))
.readValue(a2q("{'x':[ ]}")));
}
*/
Expand All @@ -116,24 +129,27 @@ public void testCanonicalConstructorPropertiesCreator() throws Exception
@Test
public void testCanonicalConstructorDelegatingIntCreator() throws Exception
{
assertEquals(POJO4584.factoryString("List[3]"),
readerWith(new DelegatingCanonicalFindingIntrospector(List.class))
.readValue(a2q("[1, 2, 3]")));
assertEquals(POJO4584.factoryString("int[42]"),
readerWith(new PrimaryCreatorFindingIntrospector(JsonCreator.Mode.DELEGATING,
Integer.TYPE))
.readValue(a2q("42")));
}

@Test
public void testCanonicalConstructorDelegatingListCreator() throws Exception
{
assertEquals(POJO4584.factoryString("List[3]"),
readerWith(new DelegatingCanonicalFindingIntrospector(List.class))
readerWith(new PrimaryCreatorFindingIntrospector(JsonCreator.Mode.DELEGATING,
List.class))
.readValue(a2q("[1, 2, 3]")));
}

@Test
public void testCanonicalConstructorDelegatingArrayCreator() throws Exception
{
assertEquals(POJO4584.factoryString("Array[1]"),
readerWith(new DelegatingCanonicalFindingIntrospector(Object[].class))
readerWith(new PrimaryCreatorFindingIntrospector(JsonCreator.Mode.DELEGATING,
Object[].class))
.readValue(a2q("[true]")));
}

Expand Down

0 comments on commit 279f69c

Please sign in to comment.