Details
-
Type: Improvement
-
Status: Closed
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
There are many requests being made to bypass the reader/writer abstractions and there are a lot of cases where it makes sense. Although using the reader/writer interfaces ensures compatability with all backing streams, sometimes it's necessary to do stream specific stuff.
Here are some examples of things Converters could do if they could use reader/writer implementation specific details:
- Copy an existing XML Element to/from the stream.
- Write non XMLy syntax (for instance a YAML ListConverter could use square brackets).
I think it's acceptable that converters should be able to cast the Reader/Writer implementation to the necessary type. However, this is not possible at the moment as the Reader/Writer is shielded behind a decorator that provides the XPath tracking.
Example of doing something syntax specific:
class YAMLListConverter implements Converter {
public void marshal(HierarichalStreamWriter writer, ...) {
{ context.convertAnother(); }YAMLWriter yamlWriter = (YAMLWriter)writer;
yamlWriter.startYAMLList();
for each blah
yamlWriter.endYAMLList();
}
}
Example of direct node manipulation:
class ElementConverter implements Converter {
public void marshal(HierarichalStreamWriter writer, ...)
{ DOMWriter domWriter = (DOMWriter)writer; Element element = (Element)source; domWriter.insertNode(element); }}