Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserialization of null values to result in JsonValue.NULL #17

Merged
merged 1 commit into from
Mar 4, 2020
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
@@ -1,7 +1,9 @@
package com.fasterxml.jackson.datatype.jsr353;

import com.fasterxml.jackson.databind.JsonMappingException;
import java.io.IOException;

import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonBuilderFactory;
import javax.json.JsonObjectBuilder;
Expand Down Expand Up @@ -36,6 +38,11 @@ public JsonValue deserialize(JsonParser p, DeserializationContext ctxt)
}
}

@Override
public Object getNullValue(final DeserializationContext ctxt){
return JsonValue.NULL;
}

@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeser)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.datatype.jsr353;

import com.fasterxml.jackson.databind.json.JsonMapper;
import javax.json.*;
import javax.json.JsonValue.ValueType;

Expand Down Expand Up @@ -100,4 +101,19 @@ public void testBinaryNode() throws Exception
String str = ((JsonString) v2).getString();
assertEquals("AA==", str); // single zero byte
}

public void testNullNode() throws Exception
{
final JsonMapper mapper = mapperBuilder().build();

final String serializedNull = mapper.writeValueAsString(JsonValue.NULL);

assertEquals("null", serializedNull);

final JsonValue deserializedNull = mapper.readValue(serializedNull, JsonValue.class);

assertNotNull(deserializedNull);

assertEquals(JsonValue.NULL, deserializedNull);
}
}