clbanning/mxj

Conversion from a null element to <element/> is broken

Closed this issue · 2 comments

I got the following example

package main

import (
	"github.com/clbanning/mxj"
	"encoding/json"
	"fmt"
	"bytes"
)

func main() {
	var data = `{"lastname":"Mustermann","phone": null}"`

	mxj.JsonUseNumber = true
	var x interface{}
	dec := json.NewDecoder(bytes.NewReader([]byte(data)))
	dec.UseNumber()
	if err := dec.Decode(&x); err != nil {
		fmt.Printf("Unmarshal: %v", err)
	}
	xx, err := mxj.AnyXmlIndent(x, "", " ", "body")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(xx))

}

Expected result is an empty phone element

<body>
 <lastname>Mustermann</lastname>
<phone/>
</body>

This is working in commit 1db1a88

but broken from commit adfeeb9

From this commit up to current master, we got this result

<body>
 <lastname>Mustermann</lastname>
<phone
</body>

Fixed on tip.

Wow, thx, quick fix. Now it is working.