本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
785B

  1. // Copyright (c) 2015, Emir Pasic. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package arraylist
  5. import (
  6. "encoding/json"
  7. "github.com/emirpasic/gods/containers"
  8. )
  9. func assertSerializationImplementation() {
  10. var _ containers.JSONSerializer = (*List)(nil)
  11. var _ containers.JSONDeserializer = (*List)(nil)
  12. }
  13. // ToJSON outputs the JSON representation of list's elements.
  14. func (list *List) ToJSON() ([]byte, error) {
  15. return json.Marshal(list.elements[:list.size])
  16. }
  17. // FromJSON populates list's elements from the input JSON representation.
  18. func (list *List) FromJSON(data []byte) error {
  19. err := json.Unmarshal(data, &list.elements)
  20. if err == nil {
  21. list.size = len(list.elements)
  22. }
  23. return err
  24. }
上海开阖软件有限公司 沪ICP备12045867号-1