You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-24 23:16:47 +02:00
#66 Make extension api like the java version
This commit is contained in:
@ -12,7 +12,6 @@ import (
|
||||
type Config struct {
|
||||
IndentionStep int
|
||||
MarshalFloatWith6Digits bool
|
||||
SupportUnexportedStructFields bool
|
||||
EscapeHtml bool
|
||||
SortMapKeys bool
|
||||
UseNumber bool
|
||||
@ -24,7 +23,7 @@ type frozenConfig struct {
|
||||
indentionStep int
|
||||
decoderCache unsafe.Pointer
|
||||
encoderCache unsafe.Pointer
|
||||
extensions []ExtensionFunc
|
||||
extensions []Extension
|
||||
streamPool chan *Stream
|
||||
iteratorPool chan *Iterator
|
||||
}
|
||||
@ -65,9 +64,6 @@ func (cfg Config) Froze() *frozenConfig {
|
||||
if cfg.MarshalFloatWith6Digits {
|
||||
frozenConfig.marshalFloatWith6Digits()
|
||||
}
|
||||
if cfg.SupportUnexportedStructFields {
|
||||
frozenConfig.supportUnexportedStructFields()
|
||||
}
|
||||
if cfg.EscapeHtml {
|
||||
frozenConfig.escapeHtml()
|
||||
}
|
||||
@ -88,17 +84,10 @@ func (cfg *frozenConfig) useNumber() {
|
||||
}})
|
||||
}
|
||||
|
||||
// RegisterExtension can register a custom extension
|
||||
func (cfg *frozenConfig) registerExtension(extension ExtensionFunc) {
|
||||
func (cfg *frozenConfig) registerExtension(extension Extension) {
|
||||
cfg.extensions = append(cfg.extensions, extension)
|
||||
}
|
||||
|
||||
func (cfg *frozenConfig) supportUnexportedStructFields() {
|
||||
cfg.registerExtension(func(type_ reflect.Type, field *reflect.StructField) ([]string, EncoderFunc, DecoderFunc) {
|
||||
return []string{field.Name}, nil, nil
|
||||
})
|
||||
}
|
||||
|
||||
type lossyFloat32Encoder struct {
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user