• Leigh McCulloch's avatar
    encoding/xml, encoding/json: docs and examples using custom marshalers · d70b0ece
    Leigh McCulloch authored
    Both the encoding/xml and encoding/json packages support custom
    marshalers for JSON and XML, as well as the basic encoding.TextMarshaler
    and encoding.TextUnmarshaler interfaces, but the docs and examples for
    these are missing.
    
    There are docs for how to use encoding.TextMarshaler and
    encoding.TextUnmarshaler in encoding/json, but not encoding/xml. There
    are no examples for how to use them with either json or xml. This commit
    includes docs for encoding/xml and examples for both encoding/json and
    encoding/xml.
    
    There is an example using custom marshalers MarshalJSON and
    UnmarshalJSON in encoding/json, but not MarshalXML and UnmarshalXML in
    encoding/json. These docs are more so necessary for encoding/xml because
    the complexities of XML documents is significantly greater than JSON
    documents which more often leads to the need for custom marshaling. The
    encoding/json package includes an example of how to write a custom
    marshaler, and this commit includes the same example for the xml
    package.
    
    All examples are mirrored off the existing custom marshaler example in
    encoding/json.
    
    Fixes #6859
    
    Change-Id: Ic93abc27c0b4d5e48dea6ede4e20b1bedca4ab39
    Reviewed-on: https://go-review.googlesource.com/c/76350
    Run-TryBot: Ian Lance Taylor <iant@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    d70b0ece
Name
Last commit
Last update
..
testdata Loading commit data...
bench_test.go Loading commit data...
decode.go Loading commit data...
decode_test.go Loading commit data...
encode.go Loading commit data...
encode_test.go Loading commit data...
example_marshaling_test.go Loading commit data...
example_test.go Loading commit data...
example_text_marshaling_test.go Loading commit data...
fold.go Loading commit data...
fold_test.go Loading commit data...
indent.go Loading commit data...
number_test.go Loading commit data...
scanner.go Loading commit data...
scanner_test.go Loading commit data...
stream.go Loading commit data...
stream_test.go Loading commit data...
tables.go Loading commit data...
tagkey_test.go Loading commit data...
tags.go Loading commit data...
tags_test.go Loading commit data...