-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Cannot access attributes from Converter
#4915
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
Comments
Sounds reasonable 🤔 |
Actually maybe just adding a new method in converter could do the trick (plus updating the relevant calls)?
|
@jakub-bochenski Yeah, this is a gap, missing info. However, I don't think |
I like the idea of improvement btw, even tho I think it can't go in 2.x. But since we are trying to get 3.0.0-rc1 ready, this would be great to get done, being API change. |
@cowtowncoder but it's not a breaking change if done as in #4915 (comment) Old implementation will continue working because of the |
@jakub-bochenski Fair enough. Although, upgrading modules that call But maybe it'd be worth tackling this for 2.x after all. Access to configuration is important and should be provided. |
The workaround I have now is I've copy-pasted the StdDelegatingSerializer and changed it's methods like this:
I'm using this to set the value before serializing the object:
this seems to work. Haven't tested it for concurrency though. TBH I'm not sure when should I use the "per-call" attributes vs the "shared" attributes. If I set them on the one-time writer() what is the difference? |
They are logically merged: so you can set "default" attributes on |
@cowtowncoder not sure if this is the right place for this discussion, but your explanation still leaves me confused :D What I observe is that So I don't really see where the per-call attributes come into the picture. |
Term "shared" in there is confusing, but basically you can both:
Use of "shared" is unfortunate since one could argue that mapper default set of attributes are actually shared, and mutable per-instance copy is NOT shared. This if my memory is correct: I haven't looked into this part of code in a while. |
@jakub-bochensk @cowtowncoder Just so we are all on same page, is this approach in our mind? |
@JooHyukKim I'd have to think about this more -- but yes the basic idea would be like that. But we'd definitely have to consider compatibility concerns carefully, whether to even consider this for 2.x, or only 3.0 (master). I haven't thought this through. (and as I mentioned elsewhere, I'll be out for a week, will then look back into this and other issues). |
Converter
Is your feature request related to a problem? Please describe.
I tried this, but the result is cached, meaning that the attribute value is always the same:
Describe the solution you'd like
Ideally Converter would have access to the MapperConfig in the
convert()
method.Maybe there could be a new interface to opt-in for this, since the signature change would be breaking.
(E.g. like ResolvableSerializer, but it would have to be called per-usage to work around caching).
Caching serializes on a per-config basis would allow the above code to work correctly.
Usage example
Additional context
Currently you have to rely on ThreadLocal or write a full custom Serializer to have access to context values. It would be nice if you could use attributes in a Converter since it's much simpler to implement than a Serializer
The text was updated successfully, but these errors were encountered: