Debian Codegraph @

maps/hashmap/serialization.go

raw symbols SCIP
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
5 package hashmap
6
7 import (
8 "encoding/json"
9
10 "github.com/emirpasic/gods/v2/containers"
11 )
12
13 // Assert Serialization implementation
14 var _ containers.JSONSerializer = (*Map[string, int])(nil)
15 var _ containers.JSONDeserializer = (*Map[string, int])(nil)
16
17 // ToJSON outputs the JSON representation of the map.
18 func (m *Map[K, V]) ToJSON() ([]byte, error) {
19 return json.Marshal(m.m)
20 }
21
22 // FromJSON populates the map from the input JSON representation.
23 func (m *Map[K, V]) FromJSON(data []byte) error {
24 return json.Unmarshal(data, &m.m)
25 }
26
27 // UnmarshalJSON @implements json.Unmarshaler
28 func (m *Map[K, V]) UnmarshalJSON(bytes []byte) error {
29 return m.FromJSON(bytes)
30 }
31
32 // MarshalJSON @implements json.Marshaler
33 func (m *Map[K, V]) MarshalJSON() ([]byte, error) {
34 return m.ToJSON()
35 }