My code is getting plastered with functions like the following:
func TransformMapClassA(mapOfIntToClassA map[int]*ClassA) map[string]*ClassA {
mapOfStringToClassA := make(map[string]*ClassA)
for id, obj := range mapOfIntToClassA {
mapOfStringToClassA[fmt.Sprintf("%d" obj.Id)] = obj
}
return mapOfStringToClassA
}
written once for each class in my application. I'm doing this, so I can json.Marshal the existing map. Is there a generic way of doing this, so I don't have to write one function per class? I've tried doing things like:
type Int64JSON int64 `json:",string"`
and using Int64JSON in my original maps, but the compiler doesn't like the json tag in a type definition :(
Many thanks in advance!