{"@context":"https://w3id.org/codemeta/3.0","@type":"SoftwareSourceCode","identifier":"pkg:golang/github.com/fjl/gencodec","name":"github.com/fjl/gencodec","description":"Command gencodec generates marshaling methods for struct types.\n\nWhen gencodec is invoked on a directory and type name, it creates a Go source file\ncontaining JSON, YAML and TOML marshaling methods for the type. The generated methods add\nfeatures which the standard json package cannot offer.\n\nThe gencodec:\"required\" tag can be used to generate a presence check for the field.\nThe generated unmarshaling method returns an error if a required field is missing.\n\nOther struct tags are carried over as is. The \"json\", \"yaml\", \"toml\" tags can be used to\nrename a field when marshaling.\n\nExample:\n\nAn invocation of gencodec can specify an additional 'field override' struct from which\nmarshaling type replacements are taken. If the override struct contains a field whose name\nmatches the original type, the generated marshaling methods will use the overridden type\nand convert to and from the original field type. If the override struct contains a field F\nof type T, which does not exist in the original type, and the original type has a method\nnamed F with no arguments and return type assignable to T, the method is called by Marshal*.\nIf there is a matching method F but the return type or arguments are unsuitable, an error\nis raised.\n\nIn this example, the specialString type implements json.Unmarshaler to enforce additional\nparsing rules. When json.Unmarshal is used with type foo, the specialString unmarshaler\nwill be used to parse the value of SpecialField. The result of foo.Func() is added to the\nresult on marshaling under the key `id`. If the input on unmarshal contains a key `id` this\nfield is ignored.\n\nField types in the override struct must be trivially convertible to the original field\ntype. gencodec's definition of 'convertible' is less restrictive than the usual rules\ndefined in the Go language specification.\n\nThe following conversions are supported:\n\nIf the fields are directly assignable, no conversion is emitted. If the fields are\nconvertible according to Go language rules, a simple conversion is emitted. Example input\ncode:\n\nThe generated code will contain:\n\nIf the fields are of map or slice type and the element (and key) types are convertible, a\nsimple loop is emitted. Example input code:\n\nThe generated code is similar to this snippet:\n\nConversions between slices and arrays are supported. Example input code:\n\nThe generated code is similar to this snippet:\n\nFor some use cases, like configuration loading, you may wish to work with structs\ncontaining fields with a non-empty interface type. Package json supports encoding such\ntypes (it simply encodes the concrete type contained in the interface), but decoding is\nnot supported. With gencodec, you can use the override struct to assign a concrete type\nthat will be used for the interface.\n\nIn the example below, the encoded struct has a field of type io.Writer. During decoding,\nthe input is verified to be \"stdout\" or \"stderr\", and the appropriate writer is inserted.","version":"v0.1.1","softwareVersion":"v0.1.1","license":"https://spdx.org/licenses/MIT","codeRepository":"https://github.com/fjl/gencodec","issueTracker":"https://github.com/fjl/gencodec/issues","url":"https://github.com/fjl/gencodec","programmingLanguage":{"@type":"ComputerLanguage","name":"Go"},"dateCreated":"2022-04-12","dateModified":"2025-03-14","datePublished":"2025-03-14","copyrightYear":2022,"downloadUrl":"https://proxy.golang.org/github.com/fjl/gencodec/@v/v0.1.1.zip","softwareHelp":{"@type":"WebSite","url":"https://pkg.go.dev/github.com/fjl/gencodec#section-documentation"},"applicationCategory":"go","runtimePlatform":"go","developmentStatus":"active","sameAs":["https://pkg.go.dev/github.com/fjl/gencodec"],"https://www.w3.org/ns/activitystreams#likes":54,"https://forgefed.org/ns#forks":28}