github.com/safing/portbase@v0.19.5/container/serialization.go (about)

     1  package container
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  // MarshalJSON serializes the container as a JSON byte array.
     8  func (c *Container) MarshalJSON() ([]byte, error) {
     9  	return json.Marshal(c.CompileData())
    10  }
    11  
    12  // UnmarshalJSON unserializes a container from a JSON byte array.
    13  func (c *Container) UnmarshalJSON(data []byte) error {
    14  	var raw []byte
    15  	if err := json.Unmarshal(data, &raw); err != nil {
    16  		return err
    17  	}
    18  
    19  	c.compartments = [][]byte{raw}
    20  	return nil
    21  }