protected IgnorePropertiesBackedByTransientFields castToPropertiesBackedByTransientFields(Object value) { if (value instanceof IgnorePropertiesBackedByTransientFields) { return (IgnorePropertiesBackedByTransientFields) value; } else { if (value != null) { if (value instanceof VisibilityChecker<?>) { return new IgnorePropertiesBackedByTransientFields((VisibilityChecker<?>) value); } LOG.warning("Could not convert value to " + "IgnorePropertiesBackedByTransientFields as was " + value.getClass().getName() + " " + value); } return null; } } protected static Field findField(String fieldName, Class<?> declaringClass) {
@Override public IgnorePropertiesBackedByTransientFields withVisibility(PropertyAccessor method, JsonAutoDetect.Visibility v) { return castToPropertiesBackedByTransientFields(defaultChecker.withVisibility(method, v)); }
protected static Field findField(String fieldName, Class<?> declaringClass) { try { return declaringClass.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { Class<?> superclass = declaringClass.getSuperclass(); if (superclass != null && superclass != declaringClass) { return findField(fieldName, superclass); } else { return null; } } } }
@Override public boolean isIsGetterVisible(Method method) { boolean answer = defaultChecker.isIsGetterVisible(method); if (answer) { answer = isGetterMethodWithFieldVisible(method, getIsGetterFieldName( method.getName()), method.getDeclaringClass()) && isGetterMethodRetItselfVisible(method, method.getDeclaringClass()); } return answer; }
@Override public boolean isGetterVisible(Method method) { boolean answer = defaultChecker.isGetterVisible(method); if (answer) { answer = isGetterMethodWithFieldVisible(method, getGetterFieldName( method.getName()), method.getDeclaringClass()) && isGetterMethodRetItselfVisible(method, method.getDeclaringClass()); } return answer; }
@Override public boolean isIsGetterVisible(Method method) { boolean answer = defaultChecker.isIsGetterVisible(method); if (answer) { answer = isGetterMethodWithFieldVisible(method, getIsGetterFieldName( method.getName()), method.getDeclaringClass()) && isGetterMethodRetItselfVisible(method, method.getDeclaringClass()); } return answer; }
@Override public boolean isGetterVisible(Method method) { boolean answer = defaultChecker.isGetterVisible(method); if (answer) { answer = isGetterMethodWithFieldVisible(method, getGetterFieldName( method.getName()), method.getDeclaringClass()) && isGetterMethodRetItselfVisible(method, method.getDeclaringClass()); } return answer; }
@Override public boolean isIsGetterVisible(AnnotatedMethod method) { boolean answer = defaultChecker.isIsGetterVisible(method); if (answer) { answer = isGetterMethodWithFieldVisible(method, getIsGetterFieldName( method.getName()), method.getDeclaringClass()) && isGetterMethodRetItselfVisible(method.getMember(), method.getDeclaringClass()); } return answer; }
@Override public boolean isGetterVisible(AnnotatedMethod method) { boolean answer = defaultChecker.isGetterVisible(method); if (answer) { answer = isGetterMethodWithFieldVisible(method, getGetterFieldName( method.getName()), method.getDeclaringClass()) && isGetterMethodRetItselfVisible(method.getMember(), method.getDeclaringClass()); } return answer; }
@Override public IgnorePropertiesBackedByTransientFields withGetterVisibility(JsonAutoDetect.Visibility v) { return castToPropertiesBackedByTransientFields(defaultChecker.withGetterVisibility(v)); }
protected static Field findField(String fieldName, Class<?> declaringClass) { try { return declaringClass.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { Class<?> superclass = declaringClass.getSuperclass(); if (superclass != null && superclass != declaringClass) { return findField(fieldName, superclass); } else { return null; } } } }
protected IgnorePropertiesBackedByTransientFields castToPropertiesBackedByTransientFields(Object value) { if (value instanceof IgnorePropertiesBackedByTransientFields) { return (IgnorePropertiesBackedByTransientFields) value; } else { if (value != null) { if (value instanceof VisibilityChecker<?>) { return new IgnorePropertiesBackedByTransientFields((VisibilityChecker<?>) value); } LOG.warning("Could not convert value to " + "IgnorePropertiesBackedByTransientFields as was " + value.getClass().getName() + " " + value); } return null; } } protected static Field findField(String fieldName, Class<?> declaringClass) {
@Override public boolean isIsGetterVisible(AnnotatedMethod method) { boolean answer = defaultChecker.isIsGetterVisible(method); if (answer) { answer = isGetterMethodWithFieldVisible(method, getIsGetterFieldName( method.getName()), method.getDeclaringClass()) && isGetterMethodRetItselfVisible(method.getMember(), method.getDeclaringClass()); } return answer; }
@Override public boolean isGetterVisible(AnnotatedMethod method) { boolean answer = defaultChecker.isGetterVisible(method); if (answer) { answer = isGetterMethodWithFieldVisible(method, getGetterFieldName( method.getName()), method.getDeclaringClass()) && isGetterMethodRetItselfVisible(method.getMember(), method.getDeclaringClass()); } return answer; }
@Override public IgnorePropertiesBackedByTransientFields withVisibility(PropertyAccessor method, JsonAutoDetect.Visibility v) { return castToPropertiesBackedByTransientFields(defaultChecker.withVisibility(method, v)); }
/** * Returns false if the getter method has a field of the same name which is transient * @return */ protected boolean isGetterMethodWithFieldVisible(Object method, String fieldName, Class<?> declaringClass) { Field field = findField(fieldName, declaringClass); if (field != null) { int fieldModifiers = field.getModifiers(); if (Modifier.isTransient(fieldModifiers)) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Ignoring getter " + method + " due to transient field called " + fieldName); } return false; } } return true; }
public void init() { LOG.log(Level.INFO, "Creating JsonSchemaLookup instance"); try { if (mapper == null) { mapper = new ObjectMapper(); mapper.setVisibility(new IgnorePropertiesBackedByTransientFields(mapper.getVisibilityChecker())); JaxbAnnotationModule module1 = new JaxbAnnotationModule(); mapper.registerModule(module1); BeanValidationAnnotationModule module2 = new BeanValidationAnnotationModule(); mapper.registerModule(module2); } // now lets expose the mbean... singleton = this; } catch (Exception e) { LOG.log(Level.WARNING, "Exception during initialization: ", e); throw new RuntimeException(e); } }
@Override public IgnorePropertiesBackedByTransientFields withSetterVisibility(JsonAutoDetect.Visibility v) { return castToPropertiesBackedByTransientFields(defaultChecker.withSetterVisibility(v)); }
/** * Returns false if the getter method has a field of the same name which is transient * @return */ protected boolean isGetterMethodWithFieldVisible(Object method, String fieldName, Class<?> declaringClass) { Field field = findField(fieldName, declaringClass); if (field != null) { int fieldModifiers = field.getModifiers(); if (Modifier.isTransient(fieldModifiers)) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Ignoring getter " + method + " due to transient field called " + fieldName); } return false; } } return true; }
public void init() { LOG.log(Level.INFO, "Creating JsonSchemaLookup instance"); try { if (mapper == null) { mapper = new ObjectMapper(); mapper.setVisibilityChecker(new IgnorePropertiesBackedByTransientFields(mapper.getVisibilityChecker())); JaxbAnnotationModule module1 = new JaxbAnnotationModule(); mapper.registerModule(module1); BeanValidationAnnotationModule module2 = new BeanValidationAnnotationModule(); mapper.registerModule(module2); } // now lets expose the mbean... singleton = this; } catch (Exception e) { LOG.log(Level.WARNING, "Exception during initialization: ", e); throw new RuntimeException(e); } }