Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 16, 2024
2 parents b332d1a + bf8f178 commit d252d60
Showing 1 changed file with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,32 @@ public static ValueInstantiator findStdValueInstantiator(DeserializationConfig c
return null;
}

private static class ArrayListInstantiator
private abstract static class JDKValueInstantiator
extends ValueInstantiator.Base
{
public final static ArrayListInstantiator INSTANCE = new ArrayListInstantiator();
public ArrayListInstantiator() {
super(ArrayList.class);
public JDKValueInstantiator(Class<?> type) {
super(type);
}

@Override
public boolean canInstantiate() { return true; }
public final boolean canInstantiate() { return true; }

@Override
public boolean canCreateUsingDefault() { return true; }
public final boolean canCreateUsingDefault() { return true; }

// Make abstract to force (re)implementation
@Override
public abstract Object createUsingDefault(DeserializationContext ctxt)
throws JacksonException;
}

private static class ArrayListInstantiator
extends JDKValueInstantiator
{
public final static ArrayListInstantiator INSTANCE = new ArrayListInstantiator();
public ArrayListInstantiator() {
super(ArrayList.class);
}

@Override
public Object createUsingDefault(DeserializationContext ctxt) throws JacksonException {
Expand All @@ -69,49 +82,37 @@ public Object createUsingDefault(DeserializationContext ctxt) throws JacksonExce
}

private static class HashMapInstantiator
extends ValueInstantiator.Base
extends JDKValueInstantiator
{
public final static HashMapInstantiator INSTANCE = new HashMapInstantiator();

public HashMapInstantiator() {
super(HashMap.class);
}

@Override
public boolean canInstantiate() { return true; }

@Override
public boolean canCreateUsingDefault() { return true; }

@Override
public Object createUsingDefault(DeserializationContext ctxt) throws JacksonException {
return new HashMap<>();
}
}

private static class LinkedHashMapInstantiator
extends ValueInstantiator.Base
extends JDKValueInstantiator
{
public final static LinkedHashMapInstantiator INSTANCE = new LinkedHashMapInstantiator();

public LinkedHashMapInstantiator() {
super(LinkedHashMap.class);
}

@Override
public boolean canInstantiate() { return true; }

@Override
public boolean canCreateUsingDefault() { return true; }

@Override
public Object createUsingDefault(DeserializationContext ctxt) throws JacksonException {
return new LinkedHashMap<>();
}
}

private static class ConstantValueInstantiator
extends ValueInstantiator.Base
extends JDKValueInstantiator
{
protected final Object _value;

Expand All @@ -120,16 +121,9 @@ public ConstantValueInstantiator(Object value) {
_value = value;
}

@Override // yes, since default ctor works
public boolean canInstantiate() { return true; }

@Override
public boolean canCreateUsingDefault() { return true; }

@Override
public Object createUsingDefault(DeserializationContext ctxt) throws JacksonException {
return _value;
}
}

}

0 comments on commit d252d60

Please sign in to comment.