Esempio n. 1
0
// FromString decode string value
func (obt *ObjectConverter) FromString(s string) (interface{}, error) {
	o := obt.ObjectFactory()
	if err := varutil.ObjectFromJSON(o, s); err != nil {
		return nil, err
	}
	return o, nil
}
Esempio n. 2
0
// ReadJSON read data from json file to object
func ReadJSON(fs filesystem.Filespace, src string, object interface{}) error {
	jsonb, err := fs.ReadFile(src)
	if err != nil {
		return err
	}
	return varutil.ObjectFromJSON(object, string(jsonb))
}
Esempio n. 3
0
func TestToPlainMapWorkWithJson(t *testing.T) {
	var sourcemap map[string]interface{}
	err := varutil.ObjectFromJSON(&sourcemap, "{\"key1\": \"1\", \"keymap\": {\"key11\": \"11\"}}")
	if err != nil {
		t.Error(err)
		return
	}

	outmap, err := ToPlainMap(sourcemap)
	if err != nil {
		t.Error(err)
		return
	}

	if outmap["key1"].(string) != "1" {
		t.Error("key1 != 1")
	}
	if outmap["keymap.key11"].(string) != "11" {
		t.Error("keymap.key11 != 11")
	}
}