2017-03-06 02:49:30 +00:00
|
|
|
// 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 arraystack
|
|
|
|
|
2021-04-08 07:19:55 +00:00
|
|
|
import (
|
|
|
|
"github.com/emirpasic/gods/containers"
|
|
|
|
)
|
2017-03-06 02:49:30 +00:00
|
|
|
|
|
|
|
func assertSerializationImplementation() {
|
|
|
|
var _ containers.JSONSerializer = (*Stack)(nil)
|
|
|
|
var _ containers.JSONDeserializer = (*Stack)(nil)
|
|
|
|
}
|
|
|
|
|
2018-09-21 02:45:26 +00:00
|
|
|
// ToJSON outputs the JSON representation of the stack.
|
2017-03-06 02:49:30 +00:00
|
|
|
func (stack *Stack) ToJSON() ([]byte, error) {
|
|
|
|
return stack.list.ToJSON()
|
|
|
|
}
|
|
|
|
|
2018-09-21 02:45:26 +00:00
|
|
|
// FromJSON populates the stack from the input JSON representation.
|
2017-03-06 02:49:30 +00:00
|
|
|
func (stack *Stack) FromJSON(data []byte) error {
|
|
|
|
return stack.list.FromJSON(data)
|
|
|
|
}
|
2021-04-08 07:19:55 +00:00
|
|
|
|
2022-04-12 02:31:44 +00:00
|
|
|
// UnmarshalJSON @implements json.Unmarshaler
|
2021-04-08 07:19:55 +00:00
|
|
|
func (stack *Stack) UnmarshalJSON(bytes []byte) error {
|
|
|
|
return stack.FromJSON(bytes)
|
|
|
|
}
|
|
|
|
|
2022-04-12 02:31:44 +00:00
|
|
|
// MarshalJSON @implements json.Marshaler
|
2021-04-08 07:19:55 +00:00
|
|
|
func (stack *Stack) MarshalJSON() ([]byte, error) {
|
|
|
|
return stack.ToJSON()
|
|
|
|
}
|