serializer

package
v0.0.0-...-b05e202 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 11 Imported by: 0

README

About serialization groups.

They allows DTO on demand

right now we use the same tag serializationGroup for input and output, which is consufing.

create and update routes are using read's config as an output which is okay in theory but in practice sometimes we do weird thing so we need to be able to give those a proper output serializationGoup for the sake of it

OR ... I would argue post/put output should be get compliant So ... allows POST proper output and use get as backup


Now, It is what's already happenning ... almost it is not for pointer and validation are a bit messy right now

goos: darwin goarch: amd64 pkg: github.com/philiphil/restman/test/serializer cpu: VirtualApple @ 2.50GHz BenchmarkSerializer_Deserialize-14 21493 55857 ns/op 5167 B/op 8 allocs/op <.> goos: darwin goarch: amd64 pkg: github.com/philiphil/restman/test/serializer cpu: VirtualApple @ 2.50GHz BenchmarkSerializer_Serialize-14 2247 489309 ns/op 348702 B/op 6268 allocs/op PASS ok github.com/phil

Documentation

Overview

the serializer package is responsible for serializing and deserializing objects its main purpose is to provide a way to exclude fields from serialization or deserialization allowing restman to generate DTO using only tags on the struct

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Serializer

type Serializer struct {
	Format  format.Format
	Compact bool
}

Serializer is responsible for serializing and deserializing objects

func NewSerializer

func NewSerializer(format format.Format) *Serializer

NewSerializer creates a new Serializer instance with the specified format.

func (*Serializer) Deserialize

func (s *Serializer) Deserialize(data string, obj any) error

Deserialize converts a string representation into an object in the configured format.

func (*Serializer) DeserializeAndMerge

func (s *Serializer) DeserializeAndMerge(data string, target any, groups ...string) error

DeserializeAndMerge deserializes data and merges it into the target object. If groups are provided, only fields with matching group tags will be merged.

func (*Serializer) MergeObjects

func (s *Serializer) MergeObjects(target any, source any, groups ...string) error

MergeObjects merges source object fields into target object, both must be pointers. If groups are provided, only fields with matching group tags will be merged.

func (*Serializer) Serialize

func (s *Serializer) Serialize(obj any, groups ...string) (string, error)

Serialize converts an object to a string representation in the configured format.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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