Skip to content

Commit

Permalink
Handle JsonNulls while deserializing (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
varshavaradarajan authored Jul 3, 2018
1 parent bfcec33 commit 28c9adc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ private boolean containsImageProperty(JsonObject jsonObject) {
}

private boolean isPropertyNotBlank(JsonObject jsonObject, String property) {
return StringUtils.isNotBlank(jsonObject.get(property).getAsString());
try {
JsonElement jsonElement = jsonObject.get(property);
return StringUtils.isNotBlank(jsonElement.getAsString());
} catch (UnsupportedOperationException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.fail;


Expand Down Expand Up @@ -61,4 +62,14 @@ public void shouldThrowAnExceptionWhenBothBuildFileAndImageAreProvided() throws
}
}
}


@Test
public void shouldParseConfigurationsWithJsonNull() throws JSONException {
String json = "{\"BuildFile\": null, \"Image\": \"alpine\"}";
ArtifactPlanConfig artifactPlanConfig = ArtifactPlanConfig.fromJSON(json);

assertThat(artifactPlanConfig).isInstanceOf(ImageTagArtifactPlanConfig.class);
assertThat(((ImageTagArtifactPlanConfig) artifactPlanConfig).getImage()).isEqualTo("alpine");
}
}

0 comments on commit 28c9adc

Please sign in to comment.