1. Andrey Somov
  2. snakeyaml
  3. Pull requests

Pull requests

#27 Open

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

Bitbucket cannot automatically merge this request.

The commits that make up this pull request have been removed.

Bitbucket cannot automatically merge this request due to conflicts.

Review the conflicts on the Overview tab. You can then either decline the request or merge it manually on your local system using the following commands:

hg update 
hg pull -r default https://bitbucket.org/RoKish/snakeyaml
  1. Roman Kishchenko


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 and JAXB have. Especially my use case is to use annotations to:

  • override property name (JsonProperty#value)
  • implement something like @JsonUnwrapped
  • ignore properties (like @JsonIgnore)

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 (only by means of reflection).

Let's say I want to ignore all the properties that are annotated with @Transient annotation. I can override Representer#representJavaBeanProperty, however currently there's no way to access annotations. With my changes it would be possible to do something like this:

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;

Actually, the commit solves the issue #307.


I added PropertyTest as my previous pull request was declined because of bad coverage. I still think, that PropertyTest more about testing PropertyUtils and BeanAccess because depending on the PropertyUtils logic, 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.

Comments (3)