Search code examples
javajsonjacksonjackson-databind

jackson databinding version 2.9.5 unable to parse the object to JSON String


We have upgraded the version of Jaxkson-databinding,jackson-core and jackson-annotation api from 2.8.2 to 2.9.5. After this upgrade my object is getting to blank json string if I am using (for 2.8.2 the same code is working fine)

        ObjectMapper mapper = new ObjectMapper();
        mapper.setVisibilityChecker(
        mapper.getVisibilityChecker().
        with(JsonAutoDetect.Visibility.NONE));

but the same works fine if I change the code to in version 2.9.5

        mapper.setVisibilityChecker(mapper.getSerializationConfig()
        .getDefaultVisibilityChecker()
        .withFieldVisibility(JsonAutoDetect.Visibility.NONE)
        .withGetterVisibility(JsonAutoDetect.Visibility.PUBLIC_ONLY)
        .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
        .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));

I can not find any change in the version upgrade relate to this in the change set of the API


Solution

  • It appears that in the first part of your code you disabled visibility of the fields on your POJO when using JsonAutoDetect.Visibility.NONE

    And in the second part you enabled visibility for public getters of your POJOs.