func registerPOJOTypeMapping()

in pojo.go [156:231]


func registerPOJOTypeMapping(javaClassName string, goName string, typ reflect.Type, o interface{}) int {
	var (
		bHeader   []byte
		bBody     []byte
		fieldList []string
		sttInfo   structInfo
		clsDef    ClassInfo
	)

	sttInfo.typ = typ
	sttInfo.goName = goName
	sttInfo.javaName = javaClassName
	sttInfo.inst = o
	pojoRegistry.j2g[sttInfo.javaName] = sttInfo.goName
	registerListNameMapping(sttInfo.goName, sttInfo.javaName)

	// prepare fields info of objectDef
	nextStruct := []reflect.Type{sttInfo.typ}
	for len(nextStruct) > 0 {
		current := nextStruct[0]
		if current.Kind() == reflect.Struct {
			for i := 0; i < current.NumField(); i++ {
				// skip unexported anonymous filed
				if current.Field(i).PkgPath != "" {
					continue
				}

				structField := current.Field(i)

				// skip ignored field
				tagVal, hasTag := structField.Tag.Lookup(tagIdentifier)
				if tagVal == `-` {
					continue
				}

				// flat anonymous field
				if structField.Anonymous && structField.Type.Kind() == reflect.Struct {
					nextStruct = append(nextStruct, structField.Type)
					continue
				}

				var fieldName string
				if hasTag {
					fieldName = tagVal
				} else {
					fieldName = lowerCamelCase(structField.Name)
				}

				fieldList = append(fieldList, fieldName)
				bBody = encString(bBody, fieldName)
			}
		}

		nextStruct = nextStruct[1:]
	}

	// prepare header of objectDef
	bHeader = encByte(bHeader, BC_OBJECT_DEF)
	bHeader = encString(bHeader, sttInfo.javaName)

	// write fields length into header of objectDef
	// note: cause fieldList is a dynamic slice, so one must calculate length only after it being prepared already.
	bHeader = encInt32(bHeader, int32(len(fieldList)))

	// prepare classDef
	clsDef = ClassInfo{javaName: sttInfo.javaName, fieldNameList: fieldList}

	// merge header and body of objectDef into buffer of ClassInfo
	clsDef.buffer = append(bHeader, bBody...)

	sttInfo.index = len(pojoRegistry.classInfoList)
	pojoRegistry.classInfoList = append(pojoRegistry.classInfoList, &clsDef)
	pojoRegistry.registry[sttInfo.goName] = &sttInfo

	return sttInfo.index
}