Skip to content

Commit b5a60a8

Browse files
committed
more work for #2989
1 parent 2e986df commit b5a60a8

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

+50
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,56 @@ public CoercionAction findCoercionFromBlankString(LogicalType targetType,
516516
return _config.findCoercionFromBlankString(targetType, targetClass, actionIfBlankNotAllowed);
517517
}
518518

519+
/*
520+
/**********************************************************************
521+
/* Factory methods for getting appropriate TokenBuffer instances
522+
/* (possibly overridden by backends for alternate data formats)
523+
/**********************************************************************
524+
*/
525+
526+
/**
527+
* Factory method used for creating {@link TokenBuffer} to temporarily
528+
* contain copy of content read from specified parser; usually for purpose
529+
* of reading contents later on (possibly augmeneted with injected additional
530+
* content)
531+
*
532+
* @since 2.13
533+
*/
534+
public TokenBuffer bufferForInputBuffering(JsonParser p) {
535+
return new TokenBuffer(p, this);
536+
}
537+
538+
/**
539+
* Convenience method that is equivalent to:
540+
*<pre>
541+
* ctxt.bufferForInputBuffering(ctxt.getParser());
542+
*</pre>
543+
*/
544+
public final TokenBuffer bufferForInputBuffering() {
545+
return bufferForInputBuffering(getParser());
546+
}
547+
548+
/**
549+
* Convenience method, equivalent to:
550+
*<pre>
551+
* TokenBuffer buffer = ctxt.bufferForInputBuffering(parser);
552+
* buffer.copyCurrentStructure(parser);
553+
* return buffer;
554+
*</pre>
555+
*<p>
556+
* NOTE: the whole "current value" that parser points to is read and
557+
* buffered, including Object and Array values (if parser pointing to
558+
* start marker).
559+
*
560+
* @since 2.9
561+
*/
562+
public TokenBuffer bufferAsCopyOfValue(JsonParser p) throws IOException
563+
{
564+
TokenBuffer buf = bufferForInputBuffering(p);
565+
buf.copyCurrentStructure(p);
566+
return buf;
567+
}
568+
519569
/*
520570
/**********************************************************
521571
/* Public API, pass-through to DeserializerCache

src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -464,27 +464,26 @@ public JsonGenerator getGenerator() {
464464
/*
465465
/**********************************************************************
466466
/* Factory methods for getting appropriate TokenBuffer instances
467-
/* (possibly overridden based on backend data format)
467+
/* (possibly overridden by backends for alternate data formats)
468468
/**********************************************************************
469469
*/
470470

471471
/**
472472
* Specialized factory method used when we are converting values and do not
473473
* typically have or use "real" parsers or generators.
474474
*
475-
* @since 3.0
475+
* @since 2.13
476476
*/
477477
public TokenBuffer bufferForValueConversion(ObjectCodec oc) {
478478
// false -> no native type/object ids
479479
return new TokenBuffer(oc, false);
480480
}
481481

482-
483482
/**
484483
* Specialized factory method used when we are converting values and do not
485484
* typically have or use "real" parsers or generators.
486485
*
487-
* @since 3.0
486+
* @since 2.13
488487
*/
489488
public final TokenBuffer bufferForValueConversion() {
490489
return bufferForValueConversion(null);

src/main/java/com/fasterxml/jackson/databind/deser/impl/ExternalTypeHandler.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ public boolean handlePropertyValue(JsonParser p, DeserializationContext ctxt,
155155
_typeIds[it.next()] = typeId;
156156
}
157157
} else {
158-
@SuppressWarnings("resource")
159-
TokenBuffer tokens = new TokenBuffer(p, ctxt);
160-
tokens.copyCurrentStructure(p);
158+
TokenBuffer tokens = ctxt.bufferAsCopyOfValue(p);
161159
_tokens[index] = tokens;
162160
while (it.hasNext()) {
163161
_tokens[it.next()] = tokens;
@@ -179,8 +177,7 @@ public boolean handlePropertyValue(JsonParser p, DeserializationContext ctxt,
179177
canDeserialize = (bean != null) && (_tokens[index] != null);
180178
} else {
181179
@SuppressWarnings("resource")
182-
TokenBuffer tokens = new TokenBuffer(p, ctxt);
183-
tokens.copyCurrentStructure(p);
180+
TokenBuffer tokens = ctxt.bufferAsCopyOfValue(p);
184181
_tokens[index] = tokens;
185182
canDeserialize = (bean != null) && (_typeIds[index] != null);
186183
}
@@ -317,7 +314,7 @@ public Object complete(JsonParser p, DeserializationContext ctxt,
317314
if (typeProp.getType().hasRawClass(String.class)) {
318315
v = typeId;
319316
} else {
320-
TokenBuffer tb = new TokenBuffer(p, ctxt);
317+
TokenBuffer tb = ctxt.bufferForInputBuffering(p);
321318
tb.writeString(typeId);
322319
v = typeProp.getValueDeserializer().deserialize(tb.asParserOnFirstToken(), ctxt);
323320
tb.close();
@@ -347,7 +344,7 @@ protected final Object _deserialize(JsonParser p, DeserializationContext ctxt,
347344
if (t == JsonToken.VALUE_NULL) {
348345
return null;
349346
}
350-
TokenBuffer merged = new TokenBuffer(p, ctxt);
347+
TokenBuffer merged = ctxt.bufferForInputBuffering(p);
351348
merged.writeStartArray();
352349
merged.writeString(typeId);
353350
merged.copyCurrentStructure(p2);
@@ -377,7 +374,7 @@ protected final void _deserializeAndSet(JsonParser p, DeserializationContext ctx
377374
_properties[index].getProperty().set(bean, null);
378375
return;
379376
}
380-
TokenBuffer merged = new TokenBuffer(p, ctxt);
377+
TokenBuffer merged = ctxt.bufferForInputBuffering(p);
381378
merged.writeStartArray();
382379
merged.writeString(typeId);
383380

src/main/java/com/fasterxml/jackson/databind/deser/std/StdKeyDeserializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public final Object deserializeKey(String key, DeserializationContext ctxt)
334334
if (key == null) { // is this even legal call?
335335
return null;
336336
}
337-
TokenBuffer tb = new TokenBuffer(ctxt.getParser(), ctxt);
337+
TokenBuffer tb = ctxt.bufferForInputBuffering();
338338
tb.writeString(key);
339339
try {
340340
// Ugh... should not have to give parser which may or may not be correct one...

0 commit comments

Comments
 (0)