 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
Examples ¶
Constants ¶
      View Source
      
  
const ErrNotInterfaceType errorkit.Error = "jsondto.ErrNotInterfaceType"
    Variables ¶
This section is empty.
Functions ¶
Types ¶
type Array ¶
type Array[T any] []T
Example ¶
package main
import (
	"encoding/json"
	"go.llib.dev/frameless/pkg/dtos/jsondto"
)
func main() {
	var greeters = jsondto.Array[Greeter]{
		TypeA{V: "42"},
		TypeB{V: 42},
	}
	data, err := json.Marshal(greeters)
	if err != nil {
		panic(err)
	}
	var result jsondto.Array[Greeter]
	if err := json.Unmarshal(data, &result); err != nil {
		panic(err)
	}
	// "result" will contain the same as the "greeters".
}
type Greeter interface{ Hello() }
type TypeA struct{ V string }
func (TypeA) Hello() {}
type TypeB struct{ V int }
func (TypeB) Hello() {}
func (Array[T]) MarshalJSON ¶
func (*Array[T]) UnmarshalJSON ¶
type Interface ¶
type Interface[I any] struct{ V I }
    Example ¶
package main
import (
	"encoding/json"
	"go.llib.dev/frameless/pkg/dtos/jsondto"
)
func main() {
	var exp = jsondto.Interface[Greeter]{
		V: &TypeC{V: 42.24},
	}
	data, err := json.Marshal(exp)
	if err != nil {
		panic(err)
	}
	// {"__type":"type_c","v":42.24}
	var got jsondto.Interface[Greeter]
	if err := json.Unmarshal(data, &got); err != nil {
		panic(err)
	}
	// got == exp
	// got.V -> *TypeC{V: 42.24}
}
type Greeter interface{ Hello() }
type TypeC struct{ V float32 }
func (*TypeC) Hello() {}
func (Interface[I]) MarshalJSON ¶
func (*Interface[I]) UnmarshalJSON ¶
 Click to show internal directories. 
   Click to hide internal directories.