@@ -1045,20 +1045,8 @@ func (r *TypeResolver) getTypeInfo(value reflect.Value, create bool) (*TypeInfo,
10451045 return ptrInfo, nil
10461046 }
10471047
1048- // Element type not registered - try auto-registration for structs
10491048 if elemType.Kind() == reflect.Struct {
1050- // First register the value type
1051- elemPkgPath := elemType.PkgPath()
1052- elemTypeName := elemType.Name()
1053- if err := r.registerStructByName(elemType, elemPkgPath, elemTypeName); err != nil {
1054- // Might already be registered, that's okay
1055- _ = err
1056- }
1057- // Now the pointer type should be registered
1058- if info, ok := r.typesInfo[type_]; ok {
1059- return info, nil
1060- }
1061- return nil, fmt.Errorf("failed to find registered pointer type %v", type_)
1049+ return nil, fmt.Errorf("struct type %s must be registered explicitly before serializing %s", elemType, type_)
10621050 }
10631051
10641052 // For primitive types and other types, we can auto-create pointer serializer
@@ -1081,6 +1069,8 @@ func (r *TypeResolver) getTypeInfo(value reflect.Value, create bool) (*TypeInfo,
10811069 return nil, fmt.Errorf("pointer element type %v must be registered", elemType)
10821070 case type_.Kind() == reflect.Interface:
10831071 return nil, fmt.Errorf("interface types must be registered explicitly")
1072+ case type_.Kind() == reflect.Struct:
1073+ return nil, fmt.Errorf("struct type %s must be registered explicitly", type_)
10841074 case pkgPath == "" && typeName == "":
10851075 // Allow anonymous collection types (maps, slices, arrays) without registration
10861076 kind := type_.Kind()
@@ -1808,23 +1798,7 @@ func (r *TypeResolver) createSerializer(type_ reflect.Type, mapInStruct bool) (s
18081798 case reflect.Struct:
18091799 serializer := r.typeToSerializers[type_]
18101800 if serializer == nil {
1811- // In xlang/compatible mode, auto-register struct types
1812- if r.isXlang || r.fory.config.Compatible {
1813- // Use the type's actual package path and name for auto-registration
1814- pkgPath := type_.PkgPath()
1815- typeName := type_.Name()
1816- if typeName == "" {
1817- return nil, fmt.Errorf("cannot auto-register anonymous struct type %s", type_.String())
1818- }
1819- // For auto-registered types, use package path as namespace and type name
1820- if err := r.registerStructByName(type_, pkgPath, typeName); err != nil {
1821- return nil, fmt.Errorf("failed to auto-register struct %s: %w", type_.String(), err)
1822- }
1823- serializer = r.typeToSerializers[type_]
1824- }
1825- if serializer == nil {
1826- return nil, fmt.Errorf("struct type %s not registered", type_.String())
1827- }
1801+ return nil, fmt.Errorf("struct type %s must be registered explicitly", type_.String())
18281802 }
18291803 return serializer, nil
18301804 }
0 commit comments