Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Additional properties serializer issues with the framework #27

Open
akomisarek opened this issue Aug 5, 2018 · 0 comments
Open

Additional properties serializer issues with the framework #27

akomisarek opened this issue Aug 5, 2018 · 0 comments

Comments

@akomisarek
Copy link

akomisarek commented Aug 5, 2018

@MartinYSpasov / @allanmckenzie

When there are no additional properties in the request, the additionalProperties map in POJO is null. This leads to NPE in AdditionalPropertiesSerializer.

Code which can be used to reproduce the issue is:

    public static void main(String[] args) throws JsonProcessingException {
        final ObjectMapper objectMapper = new ObjectMapperProducer().objectMapper();

        final ClassWithAdditionalProperties classWithAdditionalProperties = new ClassWithAdditionalProperties(3, null);
        final String serializedClassWithAdditionalProperties = objectMapper.writeValueAsString(classWithAdditionalProperties);
        System.out.println(serializedClassWithAdditionalProperties);
    }

    public static class ClassWithAdditionalProperties {
        private final int value;
        private final Map<String, Object> additionalProperties;

        public ClassWithAdditionalProperties(final int value, final Map<String, Object> additionalProperties) {
            this.value = value;
            this.additionalProperties = additionalProperties;
        }

        public int getValue() {
            return value;
        }

        public Map<String, Object> getAdditionalProperties() {
            return additionalProperties;
        }
    }

Not sure if it is better to defend against NPE (probably would work, why not?) or change the framework in another place to set the empty map...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant