Of course after posting this I found my solution. It was to use a mix-in
after all. Something like:
public abstract class FooMixIn extends Foo {
@Override
@JsonGetter("bar");
public abstract String getBar()
}
On Wednesday, July 7, 2021 at 5:41:37 PM UTC-7 John Lindwall wrote:
> We are serializing/deserializing JSON using jackson 2.11.0 and using
> visibility settings to force the use of field-level access instead of via
> setter/getters:
>
> mapper.setVisibility(PropertyAccessor.FIELD,
> JsonAutoDetect.Visibility.ANY);
> mapper.setVisibility(PropertyAccessor.GETTER,
> JsonAutoDetect.Visibility.NONE);
>
> However, certain 3rdparty classes have specific properties that we want
> generated by getter methods, and not the raw field value. We cannot modify
> these classes directly. I tried doing a mixin to make this happen but
> never figured it out. I'd prefer not to write a custom
> serializer/deserializer for this use case if possible.
>
> Here's a simplified example: If a create a Foo object (below) and
> serialize it, I'd like the output to be: {"bar": "XXbarXX"}
>
> public class Foo {
> private String bar = "bar";
>
> public String getBar() {
> return "XX" + bar + "XX";
> }
> }
>
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/4632f645-63a7-46d7-b955-b203eb3546b0n%40googlegroups.com.