eminarican/safetypes

Unmarshalling: IsSome() == true for Option if JSON property is present with null value

adbenitez opened this issue · 0 comments

example:

package main

import (
	"fmt"
	safe "github.com/eminarican/safetypes"
	"encoding/json"
)

var jsonBlob = []byte(`[
        {"Name": "Platypus"},
        {"Name": null}
    ]`)

type Animal struct {
	Name  safe.Option[string]
}

func main() {
	var animals []Animal
	json.Unmarshal(jsonBlob, &animals)

	for _, animal := range animals {
		if animal.Name.IsSome() {
			name := animal.Name.Unwrap()
			fmt.Printf("value=%q type=%T\n", name, name)
		} else {
			println("poor option :(")
		}
	}
}

even for Name: null Name.IsSome() is true, it should be false