-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
985ee58
commit 9577138
Showing
6 changed files
with
133 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/main/java/com/fasterxml/jackson/databind/deser/impl/JDKValueInstantiators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.fasterxml.jackson.databind.deser.impl; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.core.JsonLocation; | ||
import com.fasterxml.jackson.databind.DeserializationConfig; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.deser.ValueInstantiator; | ||
import com.fasterxml.jackson.databind.deser.std.JsonLocationInstantiator; | ||
|
||
/** | ||
* Container for a set of {@link ValueInstantiator}s used for certain critical | ||
* JDK value types, either as performance optimization for initialization time observed | ||
* by profiling, or due to difficulty in otherwise finding constructors. | ||
* | ||
* @since 2.10 | ||
*/ | ||
public abstract class JDKValueInstantiators | ||
{ | ||
public static ValueInstantiator findStdValueInstantiator(DeserializationConfig config, | ||
Class<?> raw) | ||
{ | ||
if (raw == JsonLocation.class) { | ||
return new JsonLocationInstantiator(); | ||
} | ||
// [databind#1868]: empty List/Set/Map | ||
if (Collection.class.isAssignableFrom(raw)) { | ||
if (raw == ArrayList.class) { | ||
return ArrayListInstantiator.INSTANCE; | ||
} | ||
// [databind#XXX]: optimize commonly needed default creators | ||
if (Collections.EMPTY_SET.getClass() == raw) { | ||
return new ConstantValueInstantiator(Collections.EMPTY_SET); | ||
} | ||
if (Collections.EMPTY_LIST.getClass() == raw) { | ||
return new ConstantValueInstantiator(Collections.EMPTY_LIST); | ||
} | ||
} else if (Map.class.isAssignableFrom(raw)) { | ||
if (raw == LinkedHashMap.class) { | ||
return LinkedHashMapInstantiator.INSTANCE; | ||
} | ||
if (Collections.EMPTY_MAP.getClass() == raw) { | ||
return new ConstantValueInstantiator(Collections.EMPTY_MAP); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private static class ArrayListInstantiator | ||
extends ValueInstantiator.Base | ||
implements java.io.Serializable | ||
{ | ||
private static final long serialVersionUID = 2L; | ||
|
||
public final static ArrayListInstantiator INSTANCE = new ArrayListInstantiator(); | ||
public ArrayListInstantiator() { | ||
super(ArrayList.class); | ||
} | ||
|
||
@Override | ||
public boolean canInstantiate() { return true; } | ||
|
||
@Override | ||
public boolean canCreateUsingDefault() { return true; } | ||
|
||
@Override | ||
public Object createUsingDefault(DeserializationContext ctxt) throws IOException { | ||
return new ArrayList<>(); | ||
} | ||
} | ||
|
||
private static class LinkedHashMapInstantiator | ||
extends ValueInstantiator.Base | ||
implements java.io.Serializable | ||
{ | ||
private static final long serialVersionUID = 2L; | ||
|
||
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 IOException { | ||
return new LinkedHashMap<>(); | ||
} | ||
} | ||
|
||
private static class ConstantValueInstantiator | ||
extends ValueInstantiator.Base | ||
implements java.io.Serializable | ||
{ | ||
private static final long serialVersionUID = 2L; | ||
|
||
protected final Object _value; | ||
|
||
public ConstantValueInstantiator(Object value) { | ||
super(value.getClass()); | ||
_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 IOException { | ||
return _value; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
src/main/java/com/fasterxml/jackson/databind/util/ConstantValueInstantiator.java
This file was deleted.
Oops, something went wrong.