Add getAnnotations() and getAnnotation(...) methods to Property

#24 Declined
Deleted repository
default (4432462a4527)
  1. Roman Kishchenko

I'm going to write my custom Presenter which would do some logic depending on property annotations. Currently there's no way to access method/field annotations. My commit adds List<Annotation> getAnnotations() and Annotation getAnnotation(...) methods to Property class.

Actually, the commit solves the issue #307.

Comments (9)

  1. Roman Kishchenko author

    @Andrey Somov Did you read the issue #307? Did you read the description?

    Let's say that I want to ignore all the properties that are annotated with @Transient annotation. To do this, I need to override Representer#representJavaBeanProperty:

    protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
        NodeTuple tuple = null;
        if (property.getAnnotation(Transient.class) == null) { // I need the getter to do this. Without the getter I can't access the annotation
            tuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
        return tuple;

    Please let me know what exactly is not clear in the sample above.

  2. Roman Kishchenko author

    1 THE WHOLE THING is very simple: as a client of SnakeYaml I want to have an access to the annotations of properties so that I could add my custom annotations like Jackson/JAXB have. Especially my use case is to use annotations to:

    Please note that I'm not going to add these annotations as a part of SnakeYaml, it's just to be used in my project that uses SnakeYaml for YAML serialization. Without this change I can't do it (I can use reflection to access private field/private PropertyDescriptor, but I'm sure, you know, that this solution is not good).

    2 From my perspective, a unit test should test only one individual component. If I write a unit test what will look like the code snippet, the test will be more about testing Representer and especially PropertyUtils and BeanAccess because depending on the logic inside PropertyUtils, FieldProperty/MethodProperty/MissingProperty is returned. Provided that PropertyUtils works as expected, there's nothing to test because it's really just a getter for annotations.

  3. Andrey Somov repo owner

    well, I think it is very clear - the pull request is declined. What kind of updates you expect ?

    If you want to create another pull request make sure that the coverage is good (all the new code must be covered by tests)