1 Star 0 Fork 0

人月神话 / gods

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
serialization.go 775 Bytes
一键复制 编辑 原始数据 按行查看 历史
人月神话 提交于 2020-11-23 12:11 . add module
// Copyright (c) 2015, Emir Pasic. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package treeset
import (
"encoding/json"
"gitee.com/lhjw9810/gods/containers"
)
func assertSerializationImplementation() {
var _ containers.JSONSerializer = (*Set)(nil)
var _ containers.JSONDeserializer = (*Set)(nil)
}
// ToJSON outputs the JSON representation of the set.
func (set *Set) ToJSON() ([]byte, error) {
return json.Marshal(set.Values())
}
// FromJSON populates the set from the input JSON representation.
func (set *Set) FromJSON(data []byte) error {
elements := []interface{}{}
err := json.Unmarshal(data, &elements)
if err == nil {
set.Clear()
set.Add(elements...)
}
return err
}
1
https://gitee.com/lhjw9810/gods.git
git@gitee.com:lhjw9810/gods.git
lhjw9810
gods
gods
v1.14.0

搜索帮助