summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/matterbridge/msgraph.go/jsonx/README.md
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-03-08 17:08:18 +0100
committerGitHub <noreply@github.com>2020-03-08 17:08:18 +0100
commit9785edd26366be8eb11c2435f50f90a5c8eea7fc (patch)
treee8e236b5b273e7535c607507cc059f3b957068a1 /vendor/github.com/matterbridge/msgraph.go/jsonx/README.md
parent2a0bc11b684f63305258e338c5f1d0e91eb24414 (diff)
downloadmatterbridge-msglm-9785edd26366be8eb11c2435f50f90a5c8eea7fc.tar.gz
matterbridge-msglm-9785edd26366be8eb11c2435f50f90a5c8eea7fc.tar.bz2
matterbridge-msglm-9785edd26366be8eb11c2435f50f90a5c8eea7fc.zip
Remove replace directives and use own fork to make go get work again (#1028)
See https://github.com/golang/go/issues/30354 go get doesn't honor the go.mod replace options.
Diffstat (limited to 'vendor/github.com/matterbridge/msgraph.go/jsonx/README.md')
-rw-r--r--vendor/github.com/matterbridge/msgraph.go/jsonx/README.md55
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/github.com/matterbridge/msgraph.go/jsonx/README.md b/vendor/github.com/matterbridge/msgraph.go/jsonx/README.md
new file mode 100644
index 00000000..949df339
--- /dev/null
+++ b/vendor/github.com/matterbridge/msgraph.go/jsonx/README.md
@@ -0,0 +1,55 @@
+# jsonx
+
+It's modified version of [encoding/json](https://golang.org/pkg/encoding/json/)
+which enables extra map field (with `jsonx:"true"` tag) to catch all other fields not declared in the struct.
+
+`jsonx` is a code name for internal use
+and not related to [JSONx](https://tools.ietf.org/html/draft-rsalz-jsonx-00).
+
+Example ([Run on playgroud](https://play.golang.org/p/TZi0JeHYG69))
+```go
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/matterbridge/msgraph.go/jsonx"
+)
+
+type Extra struct {
+ X string
+ Y int
+ Extra map[string]interface{} `json:"-" jsonx:"true"`
+}
+
+func main() {
+ var x1, x2 Extra
+ b := []byte(`{"X":"123","Y":123,"A":"123","B":123}`)
+ fmt.Printf("\nUnmarshal input: %s\n", string(b))
+ json.Unmarshal(b, &x1)
+ fmt.Printf(" json.Unmarshal: %#v\n", x1)
+ jsonx.Unmarshal(b, &x2)
+ fmt.Printf("jsonx.Unmarshal: %#v\n", x2)
+
+ x := Extra{X: "456", Y: 456, Extra: map[string]interface{}{"A": "456", "B": 456}}
+ fmt.Printf("\nMarshal input: %#v\n", x)
+ b1, _ := json.Marshal(x)
+ fmt.Printf(" json.Marshal: %s\n", string(b1))
+ b2, _ := jsonx.Marshal(x)
+ fmt.Printf("jsonx.Marshal: %s\n", string(b2))
+}
+```
+
+Result
+
+```text
+Unmarshal input: {"X":"123","Y":123,"A":"123","B":123}
+ json.Unmarshal: main.Extra{X:"123", Y:123, Extra:map[string]interface {}(nil)}
+jsonx.Unmarshal: main.Extra{X:"123", Y:123, Extra:map[string]interface {}{"A":"123", "B":123}}
+
+Marshal input: main.Extra{X:"456", Y:456, Extra:map[string]interface {}{"A":"456", "B":456}}
+ json.Marshal: {"X":"456","Y":456}
+jsonx.Marshal: {"X":"456","Y":456,"A":"456","B":456}
+```
+