Skip to content

util/gconv: compatibility for bool pointer #3764

@qinyuguang

Description

@qinyuguang

What do you want to ask?

Code

trueValue := true
falseValue := false
type T struct {
    True     bool  `json:"true"`
    False    bool  `json:"false"`
    TruePtr  *bool `json:"true_ptr"`
    FalsePtr *bool `json:"false_ptr"`
}
m := g.Map{
    "true":      trueValue,
    "false":     falseValue,
    "true_ptr":  &trueValue,
    "false_ptr": &falseValue,
}
t := &T{}
_ = gconv.Struct(m, &t)
gutil.DumpWithType(m, t)

v2.7.2 output

map[string]interface {}(4) {                                                                                                                                                                        
    string("false_ptr"): bool(false),                                                                                                                                                               
    string("true"):      bool(true),                                                                                                                                                                
    string("false"):     bool(false),                                                                                                                                                               
    string("true_ptr"):  bool(true),                                                                                                                                                                
}                                                                                                                                                                                                   
*main.T(4) {                                                                                                                                                                                        
    True:     bool(true),                                                                                                                                                                           
    False:    bool(false),                                                                                                                                                                          
    TruePtr:  bool(true),                                                                                                                                                                           
    FalsePtr: bool(false),                                                                                                                                                                          
} 

v2.7.3 output

map[string]interface {}(4) {                                                                                                                                                                        
    string("false_ptr"): bool(false),                                                                                                                                                               
    string("true"):      bool(true),                                                                                                                                                                
    string("false"):     bool(false),                                                                                                                                                               
    string("true_ptr"):  bool(true),                                                                                                                                                                
}                                                                                                                                                                                                   
*main.T(4) {                                                                                                                                                                                        
    True:     bool(true),                                                                                                                                                                           
    False:    bool(false),                                                                                                                                                                          
    TruePtr:  bool(true),                                                                                                                                                                           
    FalsePtr: bool(true),                                                                                                                                                                           
} 

Question

Need maintain compatibility when upgrading minor versions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions