Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.cloudevents.CloudEvent;
import io.cloudevents.CloudEventData;
Expand Down Expand Up @@ -175,12 +176,12 @@ private String getStringNode(ObjectNode objNode, JsonParser p, String attributeN
}

private String getOptionalStringNode(ObjectNode objNode, JsonParser p, String attributeName) throws JsonProcessingException {
JsonNode unparsedSpecVersion = objNode.remove(attributeName);
if (unparsedSpecVersion == null) {
JsonNode unparsedAttribute = objNode.remove(attributeName);
if (unparsedAttribute == null || unparsedAttribute instanceof NullNode) {
return null;
}
assertNodeType(unparsedSpecVersion, JsonNodeType.STRING, attributeName, null);
return unparsedSpecVersion.asText();
assertNodeType(unparsedAttribute, JsonNodeType.STRING, attributeName, null);
return unparsedAttribute.asText();
}

private void assertNodeType(JsonNode node, JsonNodeType type, String attributeName, String desc) throws JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

class JsonFormatTest {

private ObjectMapper mapper = new ObjectMapper();
private final ObjectMapper mapper = new ObjectMapper();

@ParameterizedTest
@MethodSource("serializeTestArgumentsDefault")
Expand Down Expand Up @@ -184,6 +184,7 @@ public static Stream<Arguments> serializeTestArgumentsBase64() {
public static Stream<Arguments> deserializeTestArguments() {
return Stream.of(
Arguments.of("v03/min.json", V03_MIN),
Arguments.of("v03/min_subject_null.json", V03_MIN),
Arguments.of("v03/json_data.json", normalizeToJsonValueIfNeeded(V03_WITH_JSON_DATA)),
Arguments.of("v03/json_data_with_ext.json", normalizeToJsonValueIfNeeded(V03_WITH_JSON_DATA_WITH_EXT)),
Arguments.of("v03/base64_json_data.json", V03_WITH_JSON_DATA),
Expand All @@ -193,6 +194,7 @@ public static Stream<Arguments> deserializeTestArguments() {
Arguments.of("v03/text_data.json", V03_WITH_TEXT_DATA),
Arguments.of("v03/base64_text_data.json", V03_WITH_TEXT_DATA),
Arguments.of("v1/min.json", V1_MIN),
Arguments.of("v1/min_subject_null.json", V1_MIN),
Arguments.of("v1/json_data.json", normalizeToJsonValueIfNeeded(V1_WITH_JSON_DATA)),
Arguments.of("v1/json_data_with_ext.json", normalizeToJsonValueIfNeeded(V1_WITH_JSON_DATA_WITH_EXT)),
Arguments.of("v1/base64_json_data.json", V1_WITH_JSON_DATA),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"specversion": "0.3",
"id": "1",
"type": "mock.test",
"source": "http://localhost/source",
"subject": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"specversion": "1.0",
"id": "1",
"type": "mock.test",
"source": "http://localhost/source",
"subject": null
}