-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
2.19Issues planned at 2.19 or laterIssues planned at 2.19 or later
Milestone
Description
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:
.setHandlerInstantiator(object : HandlerInstantiatorAdapter() {
override fun converterInstance(
config: MapperConfig<*>,
annotated: Annotated,
implClass: Class<*>
): Converter<*, *> {
if (implClass == MyConverter::class.java) {
return MyConverter {
config.attributes.getAttribute("test") as String
}
}
return implClass.newInstance() as Converter<*, *>
}
})
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
mapper.writer().withAttribute("myAttr", "Hello!").writeValueAsString(something);
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
cowtowncoder
Metadata
Metadata
Assignees
Labels
2.19Issues planned at 2.19 or laterIssues planned at 2.19 or later