Skip to content

Commit

Permalink
Support maps which are not present in the YAML, which Jackson appears…
Browse files Browse the repository at this point in the history
… to be treating differently from explicit nulls. opensearch-project#568

Signed-off-by: David Venable <[email protected]>
  • Loading branch information
dlvenable committed Nov 12, 2021
1 parent 028e47d commit 10511c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;

import java.util.HashMap;
import java.util.Map;

/**
Expand All @@ -26,11 +27,11 @@ class LogstashMappingModel implements LogstashAttributesMappings {

@JsonProperty
@JsonSetter(nulls = Nulls.AS_EMPTY)
private Map<String, String> mappedAttributeNames;
private Map<String, String> mappedAttributeNames = new HashMap<>();

@JsonProperty
@JsonSetter(nulls = Nulls.AS_EMPTY)
private Map<String, Object> additionalAttributes;
private Map<String, Object> additionalAttributes = new HashMap<>();

public String getPluginName() {
return pluginName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.IOException;

Expand Down Expand Up @@ -42,10 +44,15 @@ void deserialize_from_JSON_should_have_expected_value() throws IOException {
assertThat(logstashMappingModel.getAdditionalAttributes().get("addB"), equalTo("staticValueB"));
}

@Test
void deserialize_from_JSON_with_null_values_has_empty_lists() throws IOException {
@ParameterizedTest
@ValueSource(strings = {
"sample-with-nulls.mapping.yaml",
"sample-with-empty-maps.mapping.yaml"
})
void deserialize_from_JSON_with_null_values_has_empty_maps(final String mappingResource) throws IOException {

final LogstashMappingModel logstashMappingModel = objectMapper.readValue(this.getClass().getResourceAsStream("sample-with-nulls.mapping.yaml"), LogstashMappingModel.class);
final LogstashMappingModel logstashMappingModel =
objectMapper.readValue(this.getClass().getResourceAsStream(mappingResource), LogstashMappingModel.class);

assertThat(logstashMappingModel.getPluginName(), equalTo("samplePlugin"));
assertThat(logstashMappingModel.getAttributesMapperClass(), equalTo("org.opensearch.dataprepper.Placeholder"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pluginName: samplePlugin
attributesMapperClass: org.opensearch.dataprepper.Placeholder

0 comments on commit 10511c6

Please sign in to comment.