{"id":"27f3ee9a39d81b50","repo":"gin-gonic/gin","slug":"type-t-unknown-type","errorCode":null,"errorMessage":"type (%T) unknown type","messagePattern":"type \\(%T\\) unknown type","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"binding/plain.go","lineNumber":55,"sourceCode":"\n\tfor v.Kind() == reflect.Ptr {\n\t\tif v.IsNil() {\n\t\t\treturn nil\n\t\t}\n\t\tv = v.Elem()\n\t}\n\n\tif v.Kind() == reflect.String {\n\t\tv.SetString(bytesconv.BytesToString(data))\n\t\treturn nil\n\t}\n\n\tif _, ok := v.Interface().([]byte); ok {\n\t\tv.SetBytes(data)\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"type (%T) unknown type\", v)\n}\n","sourceCodeStart":37,"sourceCodeEnd":57,"githubUrl":"https://github.com/gin-gonic/gin/blob/34dac209ffb6ef85cc78c5d217bbb7ad001d68fd/binding/plain.go#L37-L57","documentation":"Returned by plainBinding.decodePlain (binding/plain.go:55) when the binding target — after dereferencing pointers — is neither a string nor a []byte. Plain binding just copies the raw body bytes; it has no schema parser, so any other destination type is unsupported.","triggerScenarios":"Calling binding.Plain.Bind / c.ShouldBindWith(&obj, binding.Plain) where obj points to an int, struct, map, or any non-string/[]byte type.","commonSituations":"Trying to bind a text/plain body to a struct (should use JSON or form binding); binding to *int expecting strconv conversion; pointing obj at a custom typed alias of string that does not satisfy reflect after deref (rare).","solutions":["Make the target *string or *[]byte and parse the value yourself (strconv.Atoi etc.).","If the body is actually JSON, use binding.JSON / c.ShouldBindJSON instead.","Implement binding.BindUnmarshaler on a custom type if you want plain text to populate it."],"exampleFix":"// before\nvar n int\nc.ShouldBindWith(&n, binding.Plain)\n// after\nvar raw string\nc.ShouldBindWith(&raw, binding.Plain)\nn, err := strconv.Atoi(strings.TrimSpace(raw))","handlingStrategy":"type-guard","validationCode":"v := reflect.ValueOf(obj)\nfor v.Kind() == reflect.Ptr { v = v.Elem() }\nif v.Kind() != reflect.String && v.Type() != reflect.TypeOf([]byte{}) {\n    return fmt.Errorf(\"plain binding target must be string or []byte, got %T\", obj)\n}","typeGuard":"func isPlainBindable(v any) bool {\n    rv := reflect.ValueOf(v)\n    for rv.Kind() == reflect.Ptr { rv = rv.Elem() }\n    return rv.Kind() == reflect.String || rv.Type() == reflect.TypeOf([]byte{})\n}","tryCatchPattern":"if err := c.ShouldBindWith(&raw, binding.Plain); err != nil {\n    if strings.Contains(err.Error(), \"unknown type\") {\n        // target was not string/[]byte; switch target or use a different binding\n    }\n}","preventionTips":["Bind text/plain bodies only into *string or *[]byte.","Parse the string yourself (strconv, regexp) after binding.","If the body is structured, use JSON/Form binding instead."],"tags":["binding","plain-text","go"],"analyzedSha":"34dac209ffb6ef85cc78c5d217bbb7ad001d68fd","analyzedAt":"2026-08-04T21:26:18.438Z","schemaVersion":2}