Closed semolex closed 7 months ago
I made a local copy of clover/internal/encoding.go and updated createRenameMap as follows:
func createRenameMap(rv reflect.Value) map[string]string {
renameMap := make(map[string]string)
for i := 0; i < rv.NumField(); i++ {
fieldType := rv.Type().Field(i)
tagStr, found := fieldType.Tag.Lookup("clover")
if found {
name, _ := processStructTag(tagStr)
jsonTagStr, found := fieldType.Tag.Lookup("json")
if found {
jsonName, _ := processStructTag(jsonTagStr)
if jsonName != name {
renameMap[name] = jsonName
}
} else {
renameMap[name] = fieldType.Name
}
}
}
return renameMap
}
actually, the json tag should be always be checked, not just when the clover tag is found.
@semolex: thank you for reporting the issue.
@univac490: could you submit a PR?
@semolex: please check if still have the issue. @univac490: thank you very much for fix :=)
@ostafen Thanks. Confirmed. Waiting for a next release
Hello Clover DB team,
I've encountered an issue while integrating Clover DB with the Wails framework. It seems that when using struct tags for JSON unmarshaling alongside Clover's own tags, the unmarshaled struct ends up with default values for certain fields, rather than the values stored in the database.
Environment:
Steps to Reproduce
Unmarshal the document into the struct using Clover DB's unmarshaling logic.
Expected Behavior
The struct fields should reflect the values stored in the database.
Actual Behavior
Some fields in the struct are set to their default Go values, despite having different values stored in the database.
Example
{Id:124b0a50-a6ce-4297-8718-69553f9c4222 Name:Test if marshalling works BalanceActual:0 ManagerId:"" BalanceByAccount:0 IsWorker:false}
I receive this unmarshaled result on frontend (with json-specified fields e.g.snake_case
).Is there is some undocumented way to use both tags or some designed way to specify those fields? I could definitely use are maps but in a certain way I am using type validations, possible method calls etc. Thank you for looking into this issue. I am looking forward to your response or guidance on how to address this problem.