mirror of
https://github.com/weloe/token-go.git
synced 2025-10-06 07:56:58 +08:00
feat: add JsonSerializer
This commit is contained in:
@@ -1,29 +1,10 @@
|
||||
package persist
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type JsonAdapter struct {
|
||||
*DefaultAdapter
|
||||
*JsonSerializer
|
||||
}
|
||||
|
||||
func NewJsonAdapter() *JsonAdapter {
|
||||
return &JsonAdapter{NewDefaultAdapter()}
|
||||
}
|
||||
|
||||
func (j *JsonAdapter) Serialize(data interface{}) ([]byte, error) {
|
||||
serializedData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return serializedData, nil
|
||||
}
|
||||
|
||||
func (j *JsonAdapter) UnSerialize(data []byte, result interface{}) error {
|
||||
err := json.Unmarshal(data, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return &JsonAdapter{NewDefaultAdapter(), NewJsonSerializer()}
|
||||
}
|
||||
|
Reference in New Issue
Block a user