util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalWithExtensions

func MarshalWithExtensions(v any, extensions map[string]any) ([]byte, error)

marshalWithExtensions marshals a struct with extensions inlined. This is a helper for custom MarshalJSON implementations.

IMPORTANT: When calling this function, the caller MUST use a type alias to avoid infinite recursion. For example,

func (s *MyStruct) MarshalJSON() ([]byte, error) {
    type myStruct MyStruct  // Type alias prevents recursion
    return marshalWithExtensions(myStruct(*s), s.Extensions)
}

Without the type alias, json.Marshal would recursively call MarshalJSON on the same type, causing infinite recursion. The type alias creates a new type that doesn't have the MarshalJSON method, allowing standard JSON marshaling to proceed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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