Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dotnet compatibility #11

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ import (
//
// The JSON null value unmarshals into an interface, map, pointer, or slice
// by setting that Go value to nil. Because null is often used in JSON to mean
// ``not present,'' unmarshaling a JSON null into any other Go type has no effect
// not present, unmarshaling a JSON null into any other Go type has no effect
// on the value and produces no error.
//
// When unmarshaling quoted strings, invalid UTF-8 or
// invalid UTF-16 surrogate pairs are not treated as an error.
// Instead, they are replaced by the Unicode replacement
// character U+FFFD.
//
func Unmarshal(data []byte, v interface{}) error {
// Check for well-formedness.
// Avoids filling out half a data structure
Expand Down Expand Up @@ -274,8 +273,8 @@ type decodeState struct {
Struct string
Field string
}
savedError error
useNumber bool
savedError error
useNumber bool
useOrderedObject bool
}

Expand Down
12 changes: 6 additions & 6 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ func (b *intWithPtrMarshalText) UnmarshalText(data []byte) error {
}

type unmarshalTest struct {
in string
ptr interface{}
out interface{}
err error
useNumber bool
golden bool
in string
ptr interface{}
out interface{}
err error
useNumber bool
golden bool
useOrderedObject bool
}

Expand Down
31 changes: 15 additions & 16 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,31 @@ import (
//
// Examples of struct field tags and their meanings:
//
// // Field appears in JSON as key "myName".
// Field int `json:"myName"`
// // Field appears in JSON as key "myName".
// Field int `json:"myName"`
//
// // Field appears in JSON as key "myName" and
// // the field is omitted from the object if its value is empty,
// // as defined above.
// Field int `json:"myName,omitempty"`
// // Field appears in JSON as key "myName" and
// // the field is omitted from the object if its value is empty,
// // as defined above.
// Field int `json:"myName,omitempty"`
//
// // Field appears in JSON as key "Field" (the default), but
// // the field is skipped if empty.
// // Note the leading comma.
// Field int `json:",omitempty"`
// // Field appears in JSON as key "Field" (the default), but
// // the field is skipped if empty.
// // Note the leading comma.
// Field int `json:",omitempty"`
//
// // Field is ignored by this package.
// Field int `json:"-"`
// // Field is ignored by this package.
// Field int `json:"-"`
//
// // Field appears in JSON as key "-".
// Field int `json:"-,"`
// // Field appears in JSON as key "-".
// Field int `json:"-,"`
//
// The "string" option signals that a field is stored as JSON inside a
// JSON-encoded string. It applies only to fields of string, floating point,
// integer, or boolean types. This extra level of encoding is sometimes used
// when communicating with JavaScript programs:
//
// Int64String int64 `json:",string"`
// Int64String int64 `json:",string"`
//
// The key name will be used if it's a non-empty string consisting of
// only Unicode letters, digits, and ASCII punctuation except quotation
Expand Down Expand Up @@ -161,7 +161,6 @@ import (
// JSON cannot represent cyclic data structures and Marshal does not
// handle them. Passing cyclic structures to Marshal will result in
// an infinite recursion.
//
func Marshal(v interface{}) ([]byte, error) {
e := &encodeState{}
err := e.marshal(v, encOpts{escapeHTML: true})
Expand Down
1 change: 0 additions & 1 deletion encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func (CText) MarshalText() ([]byte, error) {
return []byte(`"<&>"`), nil
}


func TestMarshaler_NeoGo_PR2174(t *testing.T) {
source := "IOU(欠条币):一种支持负数的NEP-17(非严格意义上的)资产,合约无存储区,账户由区块链浏览器统计"
b, err := Marshal(source)
Expand Down
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package json_test

import (
"bytes"
"github.com/virtuald/go-ordered-json"
"fmt"
"github.com/virtuald/go-ordered-json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

"io"
"log"
"os"
Expand Down Expand Up @@ -312,4 +312,4 @@ func ExampleOrderedObject() {
// name=André-Marie Ampère born=1777 died=1836
// Encoded:
// {"name":"Hans Christian Ørsted","born":1777,"died":1851,"nationality":"Danish"}
}
}
5 changes: 3 additions & 2 deletions fold.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ const (
// 4) simpleLetterEqualFold, no specials, no non-letters.
//
// The letters S and K are special because they map to 3 runes, not just 2:
// * S maps to s and to U+017F 'ſ' Latin small letter long s
// * k maps to K and to U+212A 'K' Kelvin sign
// - S maps to s and to U+017F 'ſ' Latin small letter long s
// - k maps to K and to U+212A 'K' Kelvin sign
//
// See https://play.golang.org/p/tTxjOc0OGo
//
// The returned function is specialized for matching against s and
Expand Down
53 changes: 26 additions & 27 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,41 +282,41 @@ type Member struct {
// OrderedObject is used to enable decoding of arbitrary JSON objects while preserving
// the order of the keys. Unmarshal and Decoder.Decode are supported.
//
// var o OrderedObject
// Unmarshal(json, &o) // decode JSON object, while preserving key order
// var o OrderedObject
// Unmarshal(json, &o) // decode JSON object, while preserving key order
//
// var oa []OrderedObject
// Unmarshal(json, &oa) // decode an array of JSON objects, while preserving key order
// var oa []OrderedObject
// Unmarshal(json, &oa) // decode an array of JSON objects, while preserving key order
//
// var v interface{}
// d := new Decoder(json)
// d.UseOrderedObject() // decode all JSON objects as OrderedObject rather than map[string]interface{}
// d.Decode(&v)
// var v interface{}
// d := new Decoder(json)
// d.UseOrderedObject() // decode all JSON objects as OrderedObject rather than map[string]interface{}
// d.Decode(&v)
//
// type A struct {
// B bool
// Inner OrderedObject
// I int
// }
// var a A
// Unmarshal(&a) // decode A as a JSON object with Inner as a nested object, preserving key order
// type A struct {
// B bool
// Inner OrderedObject
// I int
// }
// var a A
// Unmarshal(&a) // decode A as a JSON object with Inner as a nested object, preserving key order
//
// OrderedObject can also be used to encode a JSON object in
// a specified order. Marshal and Encoder.Encode are supported.
//
// var o OrderedObject
// Marshal(o) // encode JSON object, each with keys in OrderedObject order
// var o OrderedObject
// Marshal(o) // encode JSON object, each with keys in OrderedObject order
//
// var oa []OrderedObject
// Marshal(oa) // encode an array of JSON objects, with keys in OrderedObject order
// var oa []OrderedObject
// Marshal(oa) // encode an array of JSON objects, with keys in OrderedObject order
//
// type A struct {
// B bool
// Inner OrderedObject
// I int
// }
// var a A = createA()
// Marshal(a) // encode A as a JSON object with Inner as a nested object
// type A struct {
// B bool
// Inner OrderedObject
// I int
// }
// var a A = createA()
// Marshal(a) // encode A as a JSON object with Inner as a nested object
type OrderedObject []Member

// A Token holds a value of one of these types:
Expand All @@ -327,7 +327,6 @@ type OrderedObject []Member
// Number, for JSON numbers
// string, for JSON string literals
// nil, for JSON null
//
type Token interface{}

const (
Expand Down