Browse Source

codecgen: support named types in generated code properly.

When generating method names, use the same logic as for non-composite
types in the switch below.

Fixes #73
Fixes #68
Ugorji Nwoke 10 years ago
parent
commit
2542caef9f
1 changed files with 10 additions and 1 deletions
  1. 10 1
      codec/gen.go

+ 10 - 1
codec/gen.go

@@ -1420,7 +1420,16 @@ func genMethodNameT(t reflect.Type, tRef reflect.Type) (n string) {
 		t = t.Elem()
 	}
 	if tn := t.Name(); tn != "" {
-		return ptrPfx + genTypeNamePrimitiveKind(t, tRef)
+		if tRef != nil && t.PkgPath() == tRef.PkgPath() {
+			return ptrPfx + tn
+		} else {
+			tstr := t.String()
+			if genQNameRegex.MatchString(tstr) {
+				return ptrPfx + strings.Replace(tstr, ".", "_", 1000)
+			} else {
+				return ptrPfx + genCustomTypeName(tstr)
+			}
+		}
 	}
 	switch t.Kind() {
 	case reflect.Map: