-
-
Notifications
You must be signed in to change notification settings - Fork 231

Description
Background
A YAML file contains definitions that reference each other using a simple syntax:
$ cat variables.yaml
---
a: A
b: $a$ B
c: $b$ C $b$
d: $a$ $b$ $c$ D $a$
The goal is to read the YAML definitions, interpolate the values, then write them back out. The output formats include YAML and XML. YAML works fine. XML, however, does not.
For context, the YAML implementation intercepts the writeString
method of YAMLGenerator
. Note that the YAMLGenerator
class is not declared final
. The following code works:
public ResolverYAMLGenerator(
final YamlParser yamlParser,
final IOContext ctxt,
final int jsonFeatures,
final int yamlFeatures,
final ObjectCodec codec,
final Writer out,
final DumperOptions.Version version ) throws IOException {
super( ctxt, jsonFeatures, yamlFeatures, codec, out, version );
setYamlParser( yamlParser );
}
@Override
public void writeString( final String text )
throws IOException, JsonGenerationException {
final YamlParser parser = getYamlParser();
super.writeString( parser.substitute( text ) );
}
The ResolverYAMLGenerator
subclasses from YAMLGenerator
and overrides the writeString
method to perform variable interpolation via the substitute
method call.
Problem
The equivalent XML generator class, ToXmlGenerator
, is declared final. This precludes the possibility of overriding its writeString
method to perform variable interpolation.
Resolution Ideas
Can ToXmlGenerator
have its final
declaration removed?
If not, what other mechanism exists to interpolate only element values immediately prior to writing them (that don't involve composition and delegation)?