From d5304d687f488aa169ad7e5730a74e3139d799ef Mon Sep 17 00:00:00 2001 From: metalwolf Date: Mon, 13 Apr 2020 16:31:02 -0500 Subject: [PATCH 1/2] patch v0.0.12 --- README.md | 4 ++++ node.go | 15 ++++++++++----- wajaf.go | 2 +- wajaf_test.go | 6 ++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9b5db97..4723007 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ TO DO: Version Changes Control ======================= +v0.0.12 - 2020-04-13 +------------------------ +- Correction on node: JSON Marshal, wrong ',' calculations + v0.0.11 - 2020-04-13 ------------------------ - Added parameters to creation of containers, zones, dataset and elements diff --git a/node.go b/node.go index 0d82e5f..3b2c6de 100644 --- a/node.go +++ b/node.go @@ -278,19 +278,21 @@ func (n *Node) MarshalJSON() ([]byte, error) { length := len(n.attributes) candidate := length != 0 || n.ID != "" || n.Type != "" if candidate { + count := 0 buffer.WriteString(",\"attributes\":{") if n.ID != "" { + count++ buffer.WriteString("\"id\":\"" + n.ID + "\"") } if n.Type != "" { - if n.ID != "" { + if count > 0 { buffer.WriteString(",") } + count++ buffer.WriteString("\"type\":\"" + n.Type + "\"") } - count := 0 for akey, avalue := range n.attributes { - if count > 0 || n.ID != "" || n.Type != "" { + if count > 0 { buffer.WriteString(",") } if avalue == "" { @@ -309,7 +311,8 @@ func (n *Node) MarshalJSON() ([]byte, error) { // children clength := len(n.children) if clength > 0 { - buffer.WriteString(",\"children\":[") + buffer.WriteString(",") + buffer.WriteString("\"children\":[") count := 0 for _, cvalue := range n.children { if count > 0 { @@ -331,9 +334,11 @@ func (n *Node) MarshalJSON() ([]byte, error) { if err != nil { return nil, err } - buffer.WriteString(",\"data\":" + string(jsonValue)) + buffer.WriteString(",") + buffer.WriteString("\"data\":" + string(jsonValue)) } buffer.WriteString("}") + fmt.Println("JSON:", buffer.String()) return buffer.Bytes(), nil } diff --git a/wajaf.go b/wajaf.go index 084c906..0a33c05 100644 --- a/wajaf.go +++ b/wajaf.go @@ -7,7 +7,7 @@ package wajaf // VERSION is the used version nombre of the XCore library. -const VERSION = "0.0.11" +const VERSION = "0.0.12" // LOG is the flag to activate logging on the library. // if LOG is set to TRUE, LOG indicates to the XCore libraries to log a trace of functions called, with most important parameters. diff --git a/wajaf_test.go b/wajaf_test.go index c28d561..13798a8 100644 --- a/wajaf_test.go +++ b/wajaf_test.go @@ -63,6 +63,12 @@ func TestWajafLoad(t *testing.T) { // s, err := json.Marshal(app) // fmt.Println("JSON = ", string(s), err) + json, err := json.Marshal(app) + if err != nil { + fmt.Println("error json marshal", err) + return + } + fmt.Println("JSON CODE", string(json)) return } From 2709aa44feb27da90433a476f68bfcab6b7ff246 Mon Sep 17 00:00:00 2001 From: metalwolf Date: Mon, 13 Apr 2020 16:31:22 -0500 Subject: [PATCH 2/2] patch v0.0.12 --- node.go | 1 - 1 file changed, 1 deletion(-) diff --git a/node.go b/node.go index 3b2c6de..09607fd 100644 --- a/node.go +++ b/node.go @@ -339,6 +339,5 @@ func (n *Node) MarshalJSON() ([]byte, error) { } buffer.WriteString("}") - fmt.Println("JSON:", buffer.String()) return buffer.Bytes(), nil }