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

Additional properties serializer issues with the framework #27

@akomisarek

Description

@akomisarek

@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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions