apimachinery: k8s.io/apimachinery/pkg/runtime/serializer/json Index | Files

package json

import "k8s.io/apimachinery/pkg/runtime/serializer/json"

Index

Package Files

json.go meta.go

Variables

var DefaultMetaFactory = SimpleMetaFactory{}

DefaultMetaFactory is a default factory for versioning objects in JSON. The object in memory and in the default JSON serialization will use the "kind" and "apiVersion" fields.

var Framer = jsonFramer{}

Framer is the default JSON framing behavior, with newlines delimiting individual objects.

var YAMLFramer = yamlFramer{}

YAMLFramer is the default JSON framing behavior, with newlines delimiting individual objects.

func CaseSensitiveJsonIterator Uses

func CaseSensitiveJsonIterator() jsoniter.API

CaseSensitiveJsonIterator returns a jsoniterator API that's configured to be case-sensitive when unmarshalling, and otherwise compatible with the encoding/json standard library.

func StrictCaseSensitiveJsonIterator Uses

func StrictCaseSensitiveJsonIterator() jsoniter.API

StrictCaseSensitiveJsonIterator returns a jsoniterator API that's configured to be case-sensitive, but also disallows unknown fields when unmarshalling. It is compatible with the encoding/json standard library.

type MetaFactory Uses

type MetaFactory interface {
    // Interpret should return the version and kind of the wire-format of
    // the object.
    Interpret(data []byte) (*schema.GroupVersionKind, error)
}

MetaFactory is used to store and retrieve the version and kind information for JSON objects in a serializer.

type Serializer Uses

type Serializer struct {
    // contains filtered or unexported fields
}

func NewSerializer Uses

func NewSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper, pretty bool) *Serializer

NewSerializer creates a JSON serializer that handles encoding versioned objects into the proper JSON form. If typer is not nil, the object has the group, version, and kind fields set. Deprecated: use NewSerializerWithOptions instead.

func NewSerializerWithOptions Uses

func NewSerializerWithOptions(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper, options SerializerOptions) *Serializer

NewSerializerWithOptions creates a JSON/YAML serializer that handles encoding versioned objects into the proper JSON/YAML form. If typer is not nil, the object has the group, version, and kind fields set. Options are copied into the Serializer and are immutable.

func NewYAMLSerializer Uses

func NewYAMLSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper) *Serializer

NewYAMLSerializer creates a YAML serializer that handles encoding versioned objects into the proper YAML form. If typer is not nil, the object has the group, version, and kind fields set. This serializer supports only the subset of YAML that matches JSON, and will error if constructs are used that do not serialize to JSON. Deprecated: use NewSerializerWithOptions instead.

func (*Serializer) Decode Uses

func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error)

Decode attempts to convert the provided data into YAML or JSON, extract the stored schema kind, apply the provided default gvk, and then load that data into an object matching the desired schema kind or the provided into. If into is *runtime.Unknown, the raw data will be extracted and no decoding will be performed. If into is not registered with the typer, then the object will be straight decoded using normal JSON/YAML unmarshalling. If into is provided and the original data is not fully qualified with kind/version/group, the type of the into will be used to alter the returned gvk. If into is nil or data's gvk different from into's gvk, it will generate a new Object with ObjectCreater.New(gvk) On success or most errors, the method will return the calculated schema kind. The gvk calculate priority will be originalData > default gvk > into

func (*Serializer) Encode Uses

func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error

Encode serializes the provided object to the given writer.

func (*Serializer) RecognizesData Uses

func (s *Serializer) RecognizesData(peek io.Reader) (ok, unknown bool, err error)

RecognizesData implements the RecognizingDecoder interface.

type SerializerOptions Uses

type SerializerOptions struct {
    // Yaml: configures the Serializer to work with JSON(false) or YAML(true).
    // When `Yaml` is enabled, this serializer only supports the subset of YAML that
    // matches JSON, and will error if constructs are used that do not serialize to JSON.
    Yaml bool

    // Pretty: configures a JSON enabled Serializer(`Yaml: false`) to produce human-readable output.
    // This option is silently ignored when `Yaml` is `true`.
    Pretty bool

    // Strict: configures the Serializer to return strictDecodingError's when duplicate fields are present decoding JSON or YAML.
    // Note that enabling this option is not as performant as the non-strict variant, and should not be used in fast paths.
    Strict bool
}

SerializerOptions holds the options which are used to configure a JSON/YAML serializer. example: (1) To configure a JSON serializer, set `Yaml` to `false`. (2) To configure a YAML serializer, set `Yaml` to `true`. (3) To configure a strict serializer that can return strictDecodingError, set `Strict` to `true`.

type SimpleMetaFactory Uses

type SimpleMetaFactory struct {
}

SimpleMetaFactory provides default methods for retrieving the type and version of objects that are identified with an "apiVersion" and "kind" fields in their JSON serialization. It may be parameterized with the names of the fields in memory, or an optional list of base structs to search for those fields in memory.

func (SimpleMetaFactory) Interpret Uses

func (SimpleMetaFactory) Interpret(data []byte) (*schema.GroupVersionKind, error)

Interpret will return the APIVersion and Kind of the JSON wire-format encoding of an object, or an error.

Package json imports 13 packages (graph) and is imported by 85 packages. Updated 2019-04-18. Refresh now. Tools for package owners.