boj/redistore · redistore.go
go logo
func (s JSONSerializer) Deserialize(d []byte, ss *sessions.Session) error {
	m := make(map[string]interface{})
	err := json.Unmarshal(d, &m)
	if err != nil {
		fmt.Printf("redistore.JSONSerializer.deserialize() Error: %v", err)
		return err
	}
	for k, v := range m {
		ss.Values[k] = v
	}
	return nil
}
Similar code snippets
1.
sclasen/swfsm · fsm_models.go
Match rating: 61.82% · See similar code snippets
go logo
func (j JSONStateSerializer) Deserialize(serialized string, state interface{}) error {
	err := json.NewDecoder(strings.NewReader(serialized)).Decode(state)
	return err
}
2.
sclasen/swfsm · fsm_context.go
Match rating: 57.98% · See similar code snippets
go logo
func (f *FSMContext) Deserialize(serialized string, data interface{}) {
	f.serialization.Deserialize(serialized, data)
}
3.
mohae/joefriday · version_unix.go
Match rating: 54.04% · See similar code snippets
go logo
func Deserialize(p []byte) (*v.Kernel, error) {
	k := &v.Kernel{}
	err := json.Unmarshal(p, k)
	if err != nil {
		return nil, err
	}
	return k, nil
}
4.
tyler-smith/go-bip32 · bip32.go
Match rating: 53.23% · See similar code snippets
go logo
func B58Deserialize(data string) (*Key, error) {
	b, err := base58Decode(data)
	if err != nil {
		return nil, err
	}
	return Deserialize(b)
}
5.
hashicorp/consul-template · funcs.go
Match rating: 52.35% · See similar code snippets
go logo
func parseJSON(s string) (interface{}, error) {
	if s == "" {
		return map[string]interface{}{}, nil
	}

	var data interface{}
	if err := json.Unmarshal([]byte(s), &data); err != nil {
		return nil, err
	}
	return data, nil
}
6.
mohae/joefriday · mem_unix.go
Match rating: 51.23% · See similar code snippets
go logo
func Deserialize(p []byte) (*m.MemInfo, error) {
	var inf m.MemInfo
	err := json.Unmarshal(p, &inf)
	if err != nil {
		return nil, err
	}
	return &inf, nil
}
7.
openshift/origin · openid.go
Match rating: 51.09% · See similar code snippets
go logo
func getJSON(in []byte) (map[string]interface{}, error) {
	var data map[string]interface{}
	if err := json.Unmarshal(in, &data); err != nil {
		return nil, fmt.Errorf("error parsing token: %v", err)
	}
	return data, nil
}
8.
blevesearch/bleve · field.go
Match rating: 50.54% · See similar code snippets
go logo
func (fm *FieldMapping) UnmarshalJSON(data []byte) error {

	var tmp map[string]json.RawMessage
	err := json.Unmarshal(data, &tmp)
	if err != nil {
		return err
	}

	var invalidKeys []string
	for k, v := range tmp {
		switch k {
		case "name":
			err := json.Unmarshal(v, &fm.Name)
			if err != nil {
				return err
			}
		case "type":
			err := json.Unmarshal(v, &fm.Type)
			if err != nil {
				return err
			}
		case "analyzer":
			err := json.Unmarshal(v, &fm.Analyzer)
			if err != nil {
				return err
			}
		case "store":
			err := json.Unmarshal(v, &fm.Store)
			if err != nil {
				return err
			}
		case "index":
			err := json.Unmarshal(v, &fm.Index)
			if err != nil {
				return err
			}
		case "include_term_vectors":
			err := json.Unmarshal(v, &fm.IncludeTermVectors)
			if err != nil {
				return err
			}
		case "include_in_all":
			err := json.Unmarshal(v, &fm.IncludeInAll)
			if err != nil {
				return err
			}
		case "date_format":
			err := json.Unmarshal(v, &fm.DateFormat)
			if err != nil {
				return err
			}
		case "docvalues":
			err := json.Unmarshal(v, &fm.DocValues)
			if err != nil {
				return err
			}
		default:
			invalidKeys = append(invalidKeys, k)
		}
	}

	if MappingJSONStrict && len(invalidKeys) > 0 {
		return fmt.Errorf("field mapping contains invalid keys: %v", invalidKeys)
	}

	return nil
}
9.
urandom/readeef · user.go
Match rating: 50.52% · See similar code snippets
go logo
func (p *ProfileData) UnmarshalJSON(b []byte) error {
	data := map[string]json.RawMessage{}

	if err := json.Unmarshal(b, &data); err != nil {
		return errors.Wrap(err, "unmarshaling profile data")
	}

	var filters []Filter

	if len(data) > 0 {
		*p = ProfileData{}
	}

	for k, v := range data {
		switch k {
		case "filters":
			if err := json.Unmarshal(v, &filters); err != nil {
				return errors.Wrapf(err, "unmarshaling filters value %s", v)
			}
			(*p)[k] = filters
		default:
			var val interface{}

			if err := json.Unmarshal(v, &val); err != nil {
				return errors.Wrapf(err, "unmarshaling key %s value %s", k, v)
			}

			(*p)[k] = val
		}
	}

	return nil
}
10.
jyap808/go-poloniex · volume.go
Match rating: 50.49% · See similar code snippets
go logo
func (t *Volume) UnmarshalJSON(b []byte) error {
	m := make(map[string]json.RawMessage)
	if err := json.Unmarshal(b, &m); err != nil {
		return err
	}
	for k, v := range m {
		f, err := parseJSONFloatString(v)
		if err != nil {
			return err
		}
		(*t)[k] = f
	}
	return nil
}