Skip to content

Broken default for IP string in Unmarshaler #489

@JanMalch

Description

@JanMalch

I have a JSON schema with a property "address"

"address": {
    "type": "string",
    "format": "ipv4",
    "default": "127.0.0.1"
} 

which correctly generates a struct like

type Server struct {
	// Address corresponds to the JSON schema field "address".
	Address netip.Addr `json:"address,omitempty"
}

but the func UnmarshalJSON tries to set a string instead of an netip.Addr.

plain.Address = "127.0.0.1"

Should be something like so

plain.Address, err = netip.ParseAddr("127.0.0.1")
if err != nil {
   return err
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions