@@ -179,7 +179,6 @@ private Feature(boolean defaultState) {
179
179
/**********************************************************************
180
180
*/
181
181
182
-
183
182
/**
184
183
* @deprecated since 2.14, use other constructor
185
184
*/
@@ -192,16 +191,28 @@ public YAMLParser(IOContext ctxt, BufferRecycler br,
192
191
}
193
192
194
193
public YAMLParser (IOContext ctxt , int parserFeatures , int formatFeatures ,
195
- LoaderOptions loaderOptions , ObjectCodec codec , Reader reader )
194
+ LoaderOptions loaderOptions , ObjectCodec codec , Reader reader )
195
+ {
196
+ this (ctxt , parserFeatures , formatFeatures , codec , reader ,
197
+ new ParserImpl (new StreamReader (reader ),
198
+ (loaderOptions == null ) ? new LoaderOptions () : loaderOptions ));
199
+ }
200
+
201
+ /**
202
+ * Constructor to overload by custom parser sub-classes that want to replace
203
+ * {@link ParserImpl} passed.
204
+ *
205
+ * @since 2.18
206
+ */
207
+ protected YAMLParser (IOContext ctxt , int parserFeatures , int formatFeatures ,
208
+ ObjectCodec codec , Reader reader ,
209
+ ParserImpl yamlParser )
196
210
{
197
211
super (ctxt , parserFeatures );
198
212
_objectCodec = codec ;
199
213
_formatFeatures = formatFeatures ;
200
214
_reader = reader ;
201
- if (loaderOptions == null ) {
202
- loaderOptions = new LoaderOptions ();
203
- }
204
- _yamlParser = new ParserImpl (new StreamReader (reader ), loaderOptions );
215
+ _yamlParser = yamlParser ;
205
216
_cfgEmptyStringsToNull = Feature .EMPTY_STRING_AS_NULL .enabledIn (formatFeatures );
206
217
}
207
218
@@ -294,8 +305,10 @@ protected void _closeInput() throws IOException {
294
305
* Reader (granted, we only do that for UTF-32...) this
295
306
* means that buffer recycling won't work correctly.
296
307
*/
297
- if (_ioContext .isResourceManaged () || isEnabled (JsonParser .Feature .AUTO_CLOSE_SOURCE )) {
298
- _reader .close ();
308
+ if (_reader != null ) {
309
+ if (_ioContext .isResourceManaged () || isEnabled (JsonParser .Feature .AUTO_CLOSE_SOURCE )) {
310
+ _reader .close ();
311
+ }
299
312
}
300
313
}
301
314
@@ -434,7 +447,7 @@ public JsonToken nextToken() throws IOException
434
447
while (true ) {
435
448
Event evt ;
436
449
try {
437
- evt = _yamlParser . getEvent ();
450
+ evt = getEvent ();
438
451
} catch (org .yaml .snakeyaml .error .YAMLException e ) {
439
452
if (e instanceof org .yaml .snakeyaml .error .MarkedYAMLException ) {
440
453
throw com .fasterxml .jackson .dataformat .yaml .snakeyaml .error .MarkedYAMLException .from
@@ -564,6 +577,19 @@ public JsonToken nextToken() throws IOException
564
577
}
565
578
}
566
579
580
+ /**
581
+ * Since the parserImpl cannot be replaced allow subclasses to at least be able to
582
+ * influence the events being consumed.
583
+ *
584
+ * A particular use case is working around the lack of anchor and alias support to
585
+ * emit additional events.
586
+ *
587
+ * @since 2.18
588
+ */
589
+ protected Event getEvent () {
590
+ return _yamlParser .getEvent ();
591
+ }
592
+
567
593
protected JsonToken _decodeScalar (ScalarEvent scalar ) throws IOException
568
594
{
569
595
String value = scalar .getValue ();
0 commit comments