fix issue in package gjson for interface assertion of nil Json
@@ -17,6 +17,9 @@ import (
// Interface returns the json value.
func (j *Json) Interface() interface{} {
+ if j == nil {
+ return nil
+ }
j.mu.RLock()
defer j.mu.RUnlock()
return *(j.p)
@@ -29,6 +32,9 @@ func (j *Json) Var() *gvar.Var {
// IsNil checks whether the value pointed by `j` is nil.
func (j *Json) IsNil() bool {
+ if j == nil {
+ return true
+ }
j.mu.RLock()
defer j.mu.RUnlock()
return j.p == nil || *(j.p) == nil
@@ -43,6 +49,9 @@ func (j *Json) IsNil() bool {
//
// It returns a default value specified by `def` if value for `pattern` is not found.
func (j *Json) Get(pattern string, def ...interface{}) *gvar.Var {
+ if j == nil {
+ return nil
+ }
j.mu.RLock()
defer j.mu.RUnlock()
@@ -196,6 +205,9 @@ func (j *Json) Scan(pointer interface{}, mapping ...map[string]string) error {
// Dump prints current Json object with more manually readable.
func (j *Json) Dump() {
+ if j == nil {
+ return
+ }
j.mu.RLock()
defer j.mu.RUnlock()
gutil.Dump(*j.p)
