Skip to content

Allow passing ParserImpl by a subclass or overwrite the events #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,22 @@ public YAMLParser(IOContext ctxt, BufferRecycler br,
{
this(ctxt, parserFeatures, formatFeatures, null, codec, reader);
}

public YAMLParser(IOContext ctxt, int parserFeatures, int formatFeatures,
LoaderOptions loaderOptions, ObjectCodec codec, Reader reader)
{
this(ctxt, parserFeatures, formatFeatures, codec,
new ParserImpl(new StreamReader(reader), (loaderOptions == null) ? new LoaderOptions() : loaderOptions))
}

protected YAMLParser(IOContext ctxt, int parserFeatures, int formatFeatures,
ObjectCodec codec, ParserImpl yamlParser)
{
super(ctxt, parserFeatures);
_objectCodec = codec;
_formatFeatures = formatFeatures;
_reader = reader;
if (loaderOptions == null) {
loaderOptions = new LoaderOptions();
}
_yamlParser = new ParserImpl(new StreamReader(reader), loaderOptions);
_yamlParser = yamlParser;
_cfgEmptyStringsToNull = Feature.EMPTY_STRING_AS_NULL.enabledIn(formatFeatures);
}

Expand Down Expand Up @@ -415,12 +419,22 @@ protected JsonLocation _locationFor(Mark m)

// Note: SHOULD override 'getTokenLineNr', 'getTokenColumnNr', but those are final in 2.0

/**
* Since the parserImpl cannot be replaced allow subclasses to at least be able to
* influence the events being consumed.
*
* A particular use case is working around the lack of anchor and alias support to
* emit additional events.
*/
protected Event getEvent() {
return _yamlParser.getEvent();
}

/*
/**********************************************************
/* Parsing
/**********************************************************
*/

@SuppressWarnings("deprecation")
@Override
public JsonToken nextToken() throws IOException
Expand Down
Loading