-
Notifications
You must be signed in to change notification settings - Fork 42
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
Allow nested objects to be used in logging context data #142
Comments
Hi @scopendo! I tried to replicate your example and with freezed 2.0.3+1 and json_serializable 6.2.0 this works as expected so long as you do what's listed and convert the object to Json first, since json_serialziable converts those properly to strings. Generally, anything that is valid JSON will work when passed as an attribute to any call that needs accepts Can you take another look at the Map resulting from your .toJson call and see if there's another possible cause other than the enum? A nested object maybe? |
Thanks for checking @fuzzybinary – I'll take a deeper look and see what's going on with my example that's failing. It'd be great if the error message was able to better identify the map key that's causing the issue, rather than |
@scopendo Agreed, I will look into that as a separate issue. |
It looks like the issue isn't really to do with enums but more to do with nested (freezed) sub-objects. I'm still to prepare an example, however, I've found a workaround to be encoding and decoding: Datadog.instance.rum?.addTapAction('setup_done', {
'settings': jsonDecode(jsonEncode(settings.toJson())),
}); |
I think this is just a weird behavior of json_serializable that it doesn't actually serialize nested objects by default. Here's a bit more detail: It looks like if you add: @JsonSerializable(explicitToJson: true) above your class is will correctly navigate to children and serialize them to JSON with just the Let me know if that works and we can close this issue and I'll open a new one for properly logging these types of errors. |
Closing in favor of #149 |
Is your feature request related to a problem? Please describe.
It does not appear to be possible to log a data object if that object contains Dart enum values. For example, I have a data object where the class has been generated by the popular
Freezed
package, which includes attributes that are enum values. If I try to log such an object then I get an error:Here is a simplified example.
Describe the solution you'd like
Add support for logging of values that can be encoded as JSON.
The text was updated successfully, but these errors were encountered: