Skip to content

Commit 3ffdf77

Browse files
Fixes issue#113
#113
1 parent f5903d8 commit 3ffdf77

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

concurrent_map.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -324,24 +324,18 @@ func fnv32(key string) uint32 {
324324
return hash
325325
}
326326

327-
// Concurrent map uses Interface{} as its value, therefor JSON Unmarshal
328-
// will probably won't know which to type to unmarshal into, in such case
329-
// we'll end up with a value of type map[string]V, In most cases this isn't
330-
// out value type, this is why we've decided to remove this functionality.
331-
332-
// func (m *ConcurrentMap) UnmarshalJSON(b []byte) (err error) {
333-
// // Reverse process of Marshal.
334-
335-
// tmp := make(map[string]V)
336-
337-
// // Unmarshal into a single map.
338-
// if err := json.Unmarshal(b, &tmp); err != nil {
339-
// return nil
340-
// }
341-
342-
// // foreach key,value pair in temporary map insert into our concurrent map.
343-
// for key, val := range tmp {
344-
// m.Set(key, val)
345-
// }
346-
// return nil
347-
// }
327+
// Reverse process of Marshal.
328+
func (m ConcurrentMap[V]) UnmarshalJSON(b []byte) (err error) {
329+
tmp := make(map[string]V)
330+
331+
// Unmarshal into a single map.
332+
if err := json.Unmarshal(b, &tmp); err != nil {
333+
return nil
334+
}
335+
336+
// foreach key,value pair in temporary map insert into our concurrent map.
337+
for key, val := range tmp {
338+
m.Set(key, val)
339+
}
340+
return nil
341+
}

0 commit comments

Comments
 (0)