feature: added array list marshalling

master
amorozov 2024-06-25 22:18:44 +03:00
parent e6ee7860b3
commit a26b61975d
3 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package array_list
import (
"encoding/json"
)
func (a *ArrayList[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(a.content[:a.size])
}
func (a *ArrayList[T]) UnmarshalJSON(data []byte) error {
var content []T
if err := json.Unmarshal(data, &content); err != nil {
return err
}
a.content = content
a.size = len(content)
return nil
}

View File

@ -0,0 +1,20 @@
package array_list
import (
"encoding/json"
)
func (a *ArrayList[T]) MarshalXML() ([]byte, error) {
return json.Marshal(a.content[:a.size])
}
func (a *ArrayList[T]) UnmarshalXML(data []byte) error {
var content []T
if err := json.Unmarshal(data, &content); err != nil {
return err
}
a.content = content
a.size = len(content)
return nil
}

View File

@ -0,0 +1,20 @@
package array_list
import (
"encoding/json"
)
func (a *ArrayList[T]) MarshalYAML() ([]byte, error) {
return json.Marshal(a.content[:a.size])
}
func (a *ArrayList[T]) UnmarshalYAML(data []byte) error {
var content []T
if err := json.Unmarshal(data, &content); err != nil {
return err
}
a.content = content
a.size = len(content)
return nil
}