]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: remove Marshaler support
authorGustavo Niemeyer <gustavo@niemeyer.net>
Tue, 24 Jan 2012 23:51:15 +0000 (21:51 -0200)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Tue, 24 Jan 2012 23:51:15 +0000 (21:51 -0200)
Marshaler has a number of open areas that need
further thought (e.g. it doesn't handle attributes,
it's supposed to handle tag names internally but has
no information to do so, etc).

We're removing it now and will bring it back with an
interface that covers these aspects, after Go 1.

Related to issue 2771, but doesn't fix it.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5574057

src/pkg/encoding/xml/marshal.go
src/pkg/encoding/xml/marshal_test.go

index 4ef2a50eaca1efc8f777754f651645be2e0a9eeb..7a05a1bb10e711696920b4095dde5cc08ae5a7c2 100644 (file)
@@ -21,16 +21,8 @@ const (
        Header = `<?xml version="1.0" encoding="UTF-8"?>` + "\n"
 )
 
-// A Marshaler can produce well-formatted XML representing its internal state.
-type Marshaler interface {
-       MarshalXML() ([]byte, error)
-}
-
 // Marshal returns the XML encoding of v.
 //
-// If v implements Marshaler, then Marshal calls its MarshalXML method.
-// Otherwise, Marshal uses the following procedure to create the XML.
-//
 // Marshal handles an array or slice by marshalling each of the elements.
 // Marshal handles a pointer by marshalling the value it points at or, if the
 // pointer is nil, by writing nothing.  Marshal handles an interface value by
@@ -128,18 +120,6 @@ func (p *printer) marshalValue(val reflect.Value, finfo *fieldInfo) error {
        kind := val.Kind()
        typ := val.Type()
 
-       // Try Marshaler
-       if typ.NumMethod() > 0 {
-               if marshaler, ok := val.Interface().(Marshaler); ok {
-                       bytes, err := marshaler.MarshalXML()
-                       if err != nil {
-                               return err
-                       }
-                       p.Write(bytes)
-                       return nil
-               }
-       }
-
        // Drill into pointers/interfaces
        if kind == reflect.Ptr || kind == reflect.Interface {
                if val.IsNil() {
index 3bdfa55c80bbf83daa0cb46ba03f260cfaf51f97..e0be33200864e9af9ffcc346963057f644fd0b6d 100644 (file)
@@ -34,12 +34,6 @@ type Ship struct {
        secret    string
 }
 
-type RawXML string
-
-func (rx RawXML) MarshalXML() ([]byte, error) {
-       return []byte(rx), nil
-}
-
 type NamedType string
 
 type Port struct {
@@ -298,13 +292,6 @@ var marshalTests = []struct {
                UnmarshalOnly: true,
        },
 
-       // Test marshaller interface
-       {
-               Value:       RawXML("</>"),
-               ExpectXML:   `</>`,
-               MarshalOnly: true,
-       },
-
        // Test structs
        {Value: &Port{Type: "ssl", Number: "443"}, ExpectXML: `<port type="ssl">443</port>`},
        {Value: &Port{Number: "443"}, ExpectXML: `<port>443</port>`},