I'm using Johnzon 2.1.0 and like the subject says when I set the annotation in a protected/private function they are not serialized, protected/private fields do work though.

This is my test:

public class Main {

    public static class TestObject{
        public final int public_var=1;
        @JsonbProperty
        protected final int protected_var=2;
        @JsonbProperty
        private final int private_var=3;
        //
        public int getPublicFunc(){ return 1;  }
        @JsonbProperty
        protected int getProtectedFunc(){ return 2; }
        @JsonbProperty
        private int getPrivateFunc(){ return 3; }
    }

    public static void main(String[] args) throws Exception {
        JsonbConfig config = new JsonbConfig()
.withPropertyVisibilityStrategy(new PropertyVisibilityStrategy() {
                @Override
                public boolean isVisible(Field field) {
System.out.println("testing field "+field.getName());
                    return true;
                }
                @Override
                public boolean isVisible(Method method) {
System.out.println("testing method "+method.getName());
                    return true;
                }
            })
            ;
        try (Jsonb jsonb = JsonbBuilder.create(config)) {
            jsonb.toJson(new TestObject(), System.out);
        }
    }
}

The program prints the following:

testing method getPublicFunc
testing field private_var
testing field public_var
testing field protected_var
{"private_var":3,"protected_var":2,"publicFunc":1,"public_var":1}

AFAIK it should be checking all the functions (just like the fields), but it seems is not doing that. Seems private/protected functions aren't even sent to the PropertyVisibilityStrategy for testing.

Reply via email to