json-decode.go
func (cdc *Codec) decodeReflectJSONInterface(bz []byte, iinfo *TypeInfo, rv reflect.Value, fopts FieldOptions) (err error) {
	if !rv.CanAddr() {
		panic("rv not addressable")
	}
	if printLog {
		fmt.Println("(d) decodeReflectJSONInterface")
		defer func() {
			fmt.Printf("(d) -> err: %v\n", err)
		}()
	}

	/*
		We don't make use of user-provided interface values because there are a
		lot of edge cases.

		* What if the type is mismatched?
		* What if the JSON field entry is missing?
		* Circular references?
	*/
	if !rv.IsNil() {
		// We don't strictly need to set it nil, but lets keep it here for a
		// while in case we forget, for defensive purposes.
		rv.Set(iinfo.ZeroValue)
	}

	// Consume type wrapper info.
	name, bz, err := decodeInterfaceJSON(bz)
	if err != nil {
		return
	}
	// XXX: Check name against interface to make sure that it actually
	// matches, and return an error if it doesn't.

	// NOTE: Unlike decodeReflectBinaryInterface, we already dealt with nil in decodeReflectJSON.
	// NOTE: We also "consumed" the interface wrapper by replacing `bz` above.

	// Get concrete type info.
	// NOTE: Unlike decodeReflectBinaryInterface, uses the full name string.
	var cinfo *TypeInfo
	cinfo, err = cdc.getTypeInfoFromName_rlock(name)
	if err != nil {
		return
	}

	// Construct the concrete type.
	var crv, irvSet = constructConcreteType(cinfo)

	// Decode into the concrete type.
	err = cdc.decodeReflectJSON(bz, cinfo, crv, fopts)
	if err != nil {
		rv.Set(irvSet) // Helps with debugging
		return
	}

	// We need to set here, for when !PointerPreferred and the type
	// is say, an array of bytes (e.g. [32]byte), then we must call
	// rv.Set() *after* the value was acquired.
	rv.Set(irvSet)
	return
}
func (cdc *Codec) decodeReflectJSONInterface(bz []byte, iinfo *TypeInfo, rv reflect.Value, fopts FieldOptions) (err error) {
	if !rv.CanAddr() {
		panic("rv not addressable")
	}
	if printLog {
		fmt.Println("(d) decodeReflectJSONInterface")
		defer func() {
			fmt.Printf("(d) -> err: %v\n", err)
		}()
	}

	/*
		We don't make use of user-provided interface values because there are a
		lot of edge cases.

		* What if the type is mismatched?
		* What if the JSON field entry is missing?
		* Circular references?
	*/
	if !rv.IsNil() {
		// We don't strictly need to set it nil, but lets keep it here for a
		// while in case we forget, for defensive purposes.
		rv.Set(iinfo.ZeroValue)
	}

	// Consume type wrapper info.
	name, bz, err := decodeInterfaceJSON(bz)
	if err != nil {
		return
	}
	// XXX: Check name against interface to make sure that it actually
	// matches, and return an error if it doesn't.

	// NOTE: Unlike decodeReflectBinaryInterface, we already dealt with nil in decodeReflectJSON.
	// NOTE: We also "consumed" the interface wrapper by replacing `bz` above.

	// Get concrete type info.
	// NOTE: Unlike decodeReflectBinaryInterface, uses the full name string.
	var cinfo *TypeInfo
	cinfo, err = cdc.getTypeInfoFromName_rlock(name)
	if err != nil {
		return
	}

	// Construct the concrete type.
	var crv, irvSet = constructConcreteType(cinfo)

	// Decode into the concrete type.
	err = cdc.decodeReflectJSON(bz, cinfo, crv, fopts)
	if err != nil {
		rv.Set(irvSet) // Helps with debugging
		return
	}

	// We need to set here, for when !PointerPreferred and the type
	// is say, an array of bytes (e.g. [32]byte), then we must call
	// rv.Set() *after* the value was acquired.
	rv.Set(irvSet)
	return
}
// CONTRACT: rv.CanAddr() is true.