Skip to content
/ poly Public

Poly helps with polymorphic (de)serialization to and from json in golang.

License

Notifications You must be signed in to change notification settings

flachnetz/poly

Repository files navigation

Go Reference

Poly

Simple polymorphic serialization and deserialization.

type Speaker interface{ Speak() }

type Dog struct { IsDog bool }
func (Dog) Speak() {}

type Cat struct { IsCat bool }
func (Cat) Speak() {}

var animal poly.Poly[Speaker, poly.TypeList[Dog, poly.TypeList[Cat, poly.Nil]]]

// write a dog to json
animal.Value = Dog{}
bytes, _ := json.Marshal(animal)

// deserialize the dog
_ = json.Unmarshal(bytes, &animal)
animal.Value.Speak() // wuff

About

Poly helps with polymorphic (de)serialization to and from json in golang.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages