On Sat, Mar 7, 2020 at 11:15 AM Alexander <[email protected]> wrote:

> Instead of annotating many classes with this annotation, i would like to set 
> the ignoreproperties globally by default for atleast the properties with 
> these names:
>
> @JsonIgnoreProperties({
>         "JavassistLazyInitializer",
>         "hibernateLazyInitializer",
>         "handler"})
>
>
> Pointing me how this can be done will be greatly appreciated
>
>
>
There is no mechanism to ignore specifically named properties from every
class to serialize, but there are some alternatives to using
`@JsonIgnoreProperties` on a class:

1. Config overrides: you can apply equivalent of annotation on specific
classes:

   mapper.configOverride(Point.*class*)

            .setIgnorals(JsonIgnoreProperties.Value.*forIgnoredProperties*("x",
"y", "z"));

2. If you want to ignore all properties with specific type of value, either

    @JsonIgnoreType on class (possibly via mix-in annotations)

     or another config override

   mapper.configOverride(AnotherType.class)
      .setIsIgnoredType(true);

3. You can "fake" finding `@JsonIgnoreProperties` on every type, to
effectively get what you
   want by sub-classing `JacksonAnnotationIntrospector` method

    *public* JsonIgnoreProperties.Value findPropertyIgnorals(Annotated ac) {

        if (ac instanceof AnnotatedClass) { // may also check it's for
specific class(es)

           return JsonIgnoreProperties.Value.*forIgnoredProperties*("x",
"y", "z");

        }

        return JsonIgnoreProperties.Value.*empty*();

    }

Last method is probably what you want to use here.

Hope this helps!

-+ Tatu +-

-- 
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/CAGrxA26QGgs-vN3Lpg36UROWuosqmXbBAOz8Z1KoySAOgiJy3w%40mail.gmail.com.

Reply via email to