-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search response unmarshal issues #436
Comments
Hi @candiduslynx! The repo's maintainer, @alallema is on holiday. As soon as they get back, they will review your code! Thanks for the issue! |
Hi @candiduslynx, |
Sorry for the delay, It's the week of the engine release, so I'll take a look as soon as possible. |
Hello @candiduslynx,
For your first point:
I'm not sure I understand what you meant exactly, that
|
Hi @alallema
You use easyjson instead of standard
This might be actually an interesting thing to pursue, I'll take a look.
You use var v55 interface{}
if m, ok := v55.(easyjson.Unmarshaler); ok { // THIS IS AN ISSUE as v55 was just defined and is, in fact, nil
m.UnmarshalEasyJSON(in)
} else if m, ok := v55.(json.Unmarshaler); ok { // THIS IS AN ISSUE as v55 was just defined and is, in fact, nil
_ = m.UnmarshalJSON(in.Raw())
} else {
v55 = in.Interface() // End up here ALWAYS
}
It just corresponds to what is expected here, and in this case it's
|
Yes, indeed, but it should be utterly compatible with the
Thanks for the details, but this file you're talking about is auto-generated by It's not always easy to manage typing for all cases, and some of the details in this SDK are not necessarily adequate. If you have any other feedback, please don't hesitate to contact us. Thanks 😊 |
Still a problem |
I think one of the things to be used here is actually something like https://pkg.go.dev/encoding/json#Decoder.UseNumber Or https://github.com/tcolar/easyjson/blob/master/opt/gotemplate_Uint64.go |
@Ja7ad do you mind adding the PR with the fix to the issue? |
This issue is related to EasyJSON, and we currently don't have plans to fix it after 1 year. Using easyjson can improve performance in marshalling and unmarshalling, but it has limitations, especially when dealing with complex types like interface{}. Since Meilisearch returns search results as Hits with an unknown structure, the flexibility of the built-in encoding/json package might be more suitable for handling dynamic data. It offers more robust error handling, better debugging, and broader community support, albeit with slightly reduced performance. Switching to the built-in package could make the SDK more maintainable and reliable. I think we need instead use easyjson we use built-in json and we can make custom marshaller for SearchRespone and fix Interface so bad for this I think better use This is a custom unmarshaller. type SearchResponse struct {
Hits *[]map[string]interface{} `json:"hits"`
// other fields...
}
func (sr *SearchResponse) UnmarshalJSON(data []byte) error {
type Alias SearchResponse
alias := &Alias{}
if err := json.Unmarshal(data, alias); err != nil {
return err
}
var hits []map[string]interface{}
if err := json.Unmarshal(data, &hits); err != nil {
return err
}
sr.Hits = &hits
*sr = SearchResponse(*alias)
return nil
} After completing the high-priority tasks for v1.10.0 and v1.11.0, I will fix this problem, Kindly include more details about the exception in the new issue. |
@candiduslynx Please follow issue #579 |
cc @erezrokah |
Description
There are several issues with
SearchResponse
unmarshaling:in.Interface()
path perv55
being nil interfaceuint64
value (in.Interface()
->in.Float64()
that loses precision)Expected behavior
SearchResponse.Hits
unmarshaling should be addresseduint64
value (math.MaxUint64
)Current behavior
SearchResponse.Hits
always goes within.Interface()
pathmath.MaxUint64
value will lose precision per unmarshaling asfloat64
Screenshots or Logs
Stored value:
uint64(18446744073709551615)
Scanned value:
float64(9223372036854775808)
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: