1
0
mirror of https://github.com/json-iterator/go.git synced 2025-11-23 22:34:49 +02:00

# add jsoniter.RawMessage

This commit is contained in:
Tao Wen
2017-06-19 23:10:20 +08:00
parent eecb062c32
commit c6a598e292
5 changed files with 75 additions and 25 deletions

View File

@@ -79,6 +79,7 @@ var fieldEncoders map[string]Encoder
var extensions []ExtensionFunc
var jsonNumberType reflect.Type
var jsonRawMessageType reflect.Type
var jsoniterRawMessageType reflect.Type
var anyType reflect.Type
var marshalerType reflect.Type
var unmarshalerType reflect.Type
@@ -92,6 +93,7 @@ func init() {
extensions = []ExtensionFunc{}
jsonNumberType = reflect.TypeOf((*json.Number)(nil)).Elem()
jsonRawMessageType = reflect.TypeOf((*json.RawMessage)(nil)).Elem()
jsoniterRawMessageType = reflect.TypeOf((*RawMessage)(nil)).Elem()
anyType = reflect.TypeOf((*Any)(nil)).Elem()
marshalerType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
unmarshalerType = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()
@@ -296,6 +298,9 @@ func createDecoderOfType(cfg *frozenConfig, typ reflect.Type) (Decoder, error) {
if typ.AssignableTo(jsonRawMessageType) {
return &jsonRawMessageCodec{}, nil
}
if typ.AssignableTo(jsoniterRawMessageType) {
return &jsoniterRawMessageCodec{}, nil
}
if typ.AssignableTo(jsonNumberType) {
return &jsonNumberCodec{}, nil
}
@@ -386,6 +391,9 @@ func createEncoderOfType(cfg *frozenConfig, typ reflect.Type) (Encoder, error) {
if typ.AssignableTo(jsonRawMessageType) {
return &jsonRawMessageCodec{}, nil
}
if typ.AssignableTo(jsoniterRawMessageType) {
return &jsoniterRawMessageCodec{}, nil
}
if typ.AssignableTo(jsonNumberType) {
return &jsonNumberCodec{}, nil
}