Skip to content

Allow JsonPath and JsonProperty annotations on accessors #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cjbooms opened this issue Feb 4, 2015 · 0 comments
Open

Allow JsonPath and JsonProperty annotations on accessors #1

cjbooms opened this issue Feb 4, 2015 · 0 comments

Comments

@cjbooms
Copy link
Contributor

cjbooms commented Feb 4, 2015

I should be able to use the JsonPath and JsonProperty annotations on the property accessors on a class that follows JavaBean conventions.

I used the following test to determine that this functionality is not supported.

@Test
void 'In multi-level structure, with annotated setters must be unmarshalled correctly'() {
    def returnObject = new TestMultiLevelsWithAnnotatedAccessors()

    given(classInstantiator.newInstance(TestMultiLevelsWithAnnotatedAccessors))
            .willReturn(returnObject)

    def result = factory.unmarshall(TestMultiLevelsWithAnnotatedAccessors, multiLevelJson)

    def secondLevelNonAnnotated = result.getSecondLevelNonAnnotated()
    assert null != secondLevelNonAnnotated
    // ============ assert third level =======================
    def thirdLevelJProperty = secondLevelNonAnnotated.getThird_level()

    assert null != thirdLevelJProperty

    assert '3rd field1[1]' == thirdLevelJProperty.absoluteJsonPath
}

I created the following test class for use with this test

public class TestMultiLevelsWithAnnotatedAccessors {

    private SecondLevelWithAnnotatedAccessor secondLevelNonAnnotated;

    @JsonProperty("second_level")
    public void setSecondLevelNonAnnotated(final SecondLevelWithAnnotatedAccessor secondLevelNonAnnotated) {
        this.secondLevelNonAnnotated = secondLevelNonAnnotated;
    }

    public SecondLevelWithAnnotatedAccessor getSecondLevelNonAnnotated() {
        return secondLevelNonAnnotated;
    }

    /**
     * Test class.
     */
    public static final class SecondLevelWithAnnotatedAccessor {

            //CHECKSTYLE:OFF
            private ThirdLevelWithJsonPath thirdLevelWithJsonPath;
            //CHECKSTYLE:ON

            @JsonProperty("third_level")
            public void setThirdLevelWithJsonPath(final ThirdLevelWithJsonPath thirdLevelWithJsonPath) {
                    this.thirdLevelWithJsonPath = thirdLevelWithJsonPath;
            }

            public ThirdLevelWithJsonPath getThird_level() {
                   return thirdLevelWithJsonPath;
            }
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant