diff --git a/v2/internal/binding/binding.go b/v2/internal/binding/binding.go index b42718bffd2..b7794876bf2 100644 --- a/v2/internal/binding/binding.go +++ b/v2/internal/binding/binding.go @@ -350,6 +350,14 @@ func (b *Bindings) hasExportedJSONFields(typeOf reflect.Type) bool { for i := 0; i < typeOf.NumField(); i++ { jsonFieldName := "" f := typeOf.Field(i) + // function, complex, and channel types cannot be json-encoded + if f.Type.Kind() == reflect.Chan || + f.Type.Kind() == reflect.Func || + f.Type.Kind() == reflect.UnsafePointer || + f.Type.Kind() == reflect.Complex128 || + f.Type.Kind() == reflect.Complex64 { + continue + } jsonTag, hasTag := f.Tag.Lookup("json") if !hasTag && f.IsExported() { return true diff --git a/v2/internal/binding/binding_test/binding_notags_test.go b/v2/internal/binding/binding_test/binding_notags_test.go index c59a86e1b2b..d4d9997e0c0 100644 --- a/v2/internal/binding/binding_test/binding_notags_test.go +++ b/v2/internal/binding/binding_test/binding_notags_test.go @@ -5,6 +5,7 @@ type NoFieldTags struct { Address string Zip *string Spouse *NoFieldTags + NoFunc func() string } func (n NoFieldTags) Get() NoFieldTags { diff --git a/v2/internal/typescriptify/typescriptify.go b/v2/internal/typescriptify/typescriptify.go index 1d22a1b65d7..f8cb14838eb 100644 --- a/v2/internal/typescriptify/typescriptify.go +++ b/v2/internal/typescriptify/typescriptify.go @@ -553,6 +553,14 @@ func (t *TypeScriptify) getFieldOptions(structType reflect.Type, field reflect.S func (t *TypeScriptify) getJSONFieldName(field reflect.StructField, isPtr bool) string { jsonFieldName := "" + // function, complex, and channel types cannot be json-encoded + if field.Type.Kind() == reflect.Chan || + field.Type.Kind() == reflect.Func || + field.Type.Kind() == reflect.UnsafePointer || + field.Type.Kind() == reflect.Complex128 || + field.Type.Kind() == reflect.Complex64 { + return "" + } jsonTag, hasTag := field.Tag.Lookup("json") if !hasTag && field.IsExported() { jsonFieldName = field.Name diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index a0e491134cf..bbe52a84b92 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -28,7 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed incorrect TS definition of `WindowSetSize` by @leaanthony - chore: fix some comments in [PR](https://github.com/wailsapp/wails/pull/3932) by @lvyaoting - [windows] Fixed frameless window flickering when minimizing/restoring by preventing unnecessary redraws [#3951](https://github.com/wailsapp/wails/issues/3951) - +- Fixed failed models.ts build due to non-json-encodable Go types [PR](https://github.com/wailsapp/wails/pull/3975) by [@pbnjay](https://github.com/pbnjay) ### Changed - Allow to specify macos-min-version externally. Implemented by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/3756)