Skip to content

Commit

Permalink
Fix #3473 (re-implementation of #2816 for 2.14)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 31, 2022
1 parent f0af53d commit 8238ab4
Show file tree
Hide file tree
Showing 6 changed files with 666 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
if ((_stringDeserializer == null) && (_numberDeserializer == null)
&& (_mapDeserializer == null) && (_listDeserializer == null)
&& getClass() == UntypedObjectDeserializer.class) {
return Vanilla.instance(preventMerge);
return UntypedObjectDeserializerNR.instance(preventMerge);
}

if (preventMerge != _nonMerging) {
Expand Down Expand Up @@ -659,6 +659,7 @@ protected Object mapObject(JsonParser p, DeserializationContext ctxt,
* is only used when no custom deserializer overrides are applied.
*/
@JacksonStdImpl
@Deprecated // since 2.14, to be removed in near future
public static class Vanilla
extends StdDeserializer<Object>
{
Expand Down Expand Up @@ -869,18 +870,10 @@ protected Object mapArray(JsonParser p, DeserializationContext ctxt) throws IOEx
l.add(value);
return l;
}
Object value2 = deserialize(p, ctxt);
if (p.nextToken() == JsonToken.END_ARRAY) {
ArrayList<Object> l = new ArrayList<Object>(2);
l.add(value);
l.add(value2);
return l;
}
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
values[ptr++] = value;
values[ptr++] = value2;
int totalSize = ptr;
do {
value = deserialize(p, ctxt);
Expand All @@ -898,9 +891,6 @@ protected Object mapArray(JsonParser p, DeserializationContext ctxt) throws IOEx
return result;
}

/**
* Method called to map a JSON Array into a Java Object array (Object[]).
*/
protected Object[] mapArrayToArray(JsonParser p, DeserializationContext ctxt) throws IOException {
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
Expand All @@ -918,9 +908,6 @@ protected Object[] mapArrayToArray(JsonParser p, DeserializationContext ctxt) th
return result;
}

/**
* Method called to map a JSON Object into a Java value.
*/
protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOException
{
// will point to FIELD_NAME at this point, guaranteed
Expand All @@ -929,33 +916,15 @@ protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOE
p.nextToken();
Object value1 = deserialize(p, ctxt);

String key2 = p.nextFieldName();
if (key2 == null) { // single entry; but we want modifiable
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(2);
result.put(key1, value1);
return result;
}
p.nextToken();
Object value2 = deserialize(p, ctxt);

String key = p.nextFieldName();
if (key == null) {
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(4);
if (key == null) { // single entry; but we want modifiable
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(2);
result.put(key1, value1);
if (result.put(key2, value2) != null) {
// 22-May-2020, tatu: [databind#2733] may need extra handling
return _mapObjectWithDups(p, ctxt, result, key1, value1, value2, key);
}
return result;
}
// And then the general case; default map size is 16
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
result.put(key1, value1);
if (result.put(key2, value2) != null) {
// 22-May-2020, tatu: [databind#2733] may need extra handling
return _mapObjectWithDups(p, ctxt, result, key1, value1, value2, key);
}

do {
p.nextToken();
final Object newValue = deserialize(p, ctxt);
Expand Down
Loading

0 comments on commit 8238ab4

Please sign in to comment.