adapters

package
v0.25.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package adapters exposes a registry of adapters to multiple JSON serialization libraries.

All interfaces are defined in package ifaces.Adapter.

Index

Constants

This section is empty.

Variables

View Source
var ErrRegistry registryError = "JSON adapters registry error"

ErrRegistry indicates an error returned by the Registrar.

View Source
var Registry = NewRegistrar()

Registry holds the global registry for registered adapters.

Functions

func MarshalAdapterFor

func MarshalAdapterFor(value any) ifaces.MarshalAdapter

MarshalAdapterFor returns the first adapter that knows how to Marshal this type of value.

func NewOrderedMap

func NewOrderedMap(capacity int) ifaces.OrderedMap

NewOrderedMap provides the "ordered map" implementation provided by the registry.

func OrderedMarshalAdapterFor

func OrderedMarshalAdapterFor(value ifaces.Ordered) ifaces.OrderedMarshalAdapter

OrderedMarshalAdapterFor returns the first adapter that knows how to OrderedMarshal this type of value.

func OrderedUnmarshalAdapterFor

func OrderedUnmarshalAdapterFor(value ifaces.SetOrdered) ifaces.OrderedUnmarshalAdapter

OrderedUnmarshalAdapterFor provides the first adapter that knows how to OrderedUnmarshal this type of value.

func UnmarshalAdapterFor

func UnmarshalAdapterFor(value any) ifaces.UnmarshalAdapter

UnmarshalAdapterFor returns the first adapter that knows how to Unmarshal this type of value.

Types

type Registrar

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

Registrar holds registered ifaces.Adapters for different serialization capabilities.

Internally, it maintains a cache for data types that favor a given adapter.

func NewRegistrar

func NewRegistrar() *Registrar

func (*Registrar) AdapterFor

func (r *Registrar) AdapterFor(capability ifaces.Capability, value any) ifaces.Adapter

AdapterFor returns an ifaces.Adapter that supports this capability for this type of value.

The ifaces.Adapter may be redeemed to its pool using its Redeem() method, for adapters that support global pooling. When this is not the case, the redeem function is just a no-operation.

func (*Registrar) ClearCache

func (r *Registrar) ClearCache()

ClearCache resets the internal type cache.

func (*Registrar) RegisterFor

func (r *Registrar) RegisterFor(entry ifaces.RegistryEntry)

RegisterFor registers an adapter for some JSON capabilities.

func (*Registrar) Reset

func (r *Registrar) Reset()

Reset the Registrar to its defaults.

Directories

Path Synopsis
easyjson module
Package ifaces exposes all interfaces to work with adapters.
Package ifaces exposes all interfaces to work with adapters.
Package stdlib exposes a JSON adapter built on top of the standard library.
Package stdlib exposes a JSON adapter built on top of the standard library.
json
Package json implements an ifaces.Adapter using the standard library.
Package json implements an ifaces.Adapter using the standard library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL