-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
Implement class serializers and interface to customize how objects are serialized #809
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat idea!
I would just object on two small naming things...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, LGTM now! 👍
322e77d
to
ea91bea
Compare
I see a few drawbacks in this implementation:
Said this I obviously see the value of such feature, but I'm not convinced that this is the way to go |
The user get's the object passed so we could allow a null return value to skip the serializer and default back to the regular serialization to fix this?
Their own serializer will work just fine... it won't magically replace their serializer. If they want to switch they can, if they don't they don't...
Please convince me about a better way forward than 😉 |
ea91bea
to
ce4461a
Compare
I did make a change which allows the user to register a Also allowing to return The only "issue" here is sorting, because the order you register serializers in the |
Thinking more about this feature, if someone wants to customize how objects are serialized or represented then the best way is to write their own serializer, which is why the |
@ste93cry I think I got all your suggestions in, good ones! |
Build failing due to CS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a few things left to fix, but overall it seems good
2aa572f
to
d4a0629
Compare
This reverts commit 60e0417.
It was a choice made. In hindsight might have been better to allow for strings to. Design was for serializing objects (key-value) in mind mostly. I think we can broaden it to allow for strings or other scalar types without BC but not 100% sure. It does have to be a type supported by json_encode so some form of check should stay probably so were not trying to encode objects as json anyhow. |
This allows the user (or framework library) to implement their own serialized values for any object instead of the
Object SomeObject
string that Sentry now shows.Usage with interface (for object of your own):
Usage with serializer "helper" for objects you don't control, register via an option
class_serializers
.If a custom serializer or
toSentry()
generates an exception the value is discarded and the serializers serializes it as normal (resulting in aObject ExampleClass
string). This is to prevent any issues caused by bad serializers or problems that occur there that might mask the actual exception that we are trying to send/serialize.The
class_serializers
are resolved usinginstanceof
to allow the user to add a custom serializer for a parent class or interface.Currently it creates an array with the data nested to make it clear which class it actually is, this might be a concern because of the max depth but probably is not.
/ref #443 #316