Skip to content

Fix getNullValue of IonValueDeserializer. #319

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

Closed
wants to merge 3 commits into from
Closed
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 @@ -14,6 +14,8 @@

package com.fasterxml.jackson.dataformat.ion.ionvalue;

import com.amazon.ion.IonNull;
import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
Expand Down Expand Up @@ -58,11 +60,15 @@ public IonValue deserialize(JsonParser jp, DeserializationContext ctxt) throws I
@Override
public IonValue getNullValue(DeserializationContext ctxt) throws JsonMappingException {
try {
Object embeddedObj = ctxt.getParser().getEmbeddedObject();
if (embeddedObj instanceof IonValue) {
IonValue iv = (IonValue) embeddedObj;
if (iv.isNullValue()) {
return iv;
final JsonParser parser = ctxt.getParser();
if (parser != null && parser.getCurrentToken() != JsonToken.END_OBJECT) {
final Object embeddedObj = parser.getEmbeddedObject();
if ((embeddedObj instanceof IonValue)
&& ( (parser.getTypeId() != null) || !(embeddedObj instanceof IonNull))) {
final IonValue iv = (IonValue) embeddedObj;
if (iv.isNullValue()) {
return iv;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,70 @@ public void shouldBeAbleToDeserializeNullStruct() throws Exception {

@Test
public void shouldBeAbleToDeserializeNullValue() throws Exception {
IonValue ion = SYSTEM.newNull();
IonValueData source = new IonValueData();
source.put("a", null); // Serialized to IonNull, deserialized back to java null
source.put("b", ion("null.bool"));
source.put("ba", ion("foo::null.bool"));
source.put("c", ion("null.int"));
source.put("ca", ion("foo::null.int"));
source.put("d", ion("null.float"));
source.put("da", ion("foo::null.float"));
source.put("e", ion("null.decimal"));
source.put("ea", ion("foo::null.decimal"));
source.put("f", ion("null.timestamp"));
source.put("fa", ion("foo::null.timestamp"));
source.put("g", ion("null.string"));
source.put("ga", ion("foo::null.string"));
source.put("h", ion("null.symbol"));
source.put("ha", ion("foo::null.symbol"));
source.put("i", ion("null.blob"));
source.put("ia", ion("foo::null.blob"));
source.put("j", ion("null.clob"));
source.put("ja", ion("foo::null.clob"));
source.put("k", ion("null.struct"));
source.put("ka", ion("foo::null.struct"));
source.put("l", ion("null.list"));
source.put("la", ion("foo::null.list"));
source.put("m", ion("null.sexp"));
source.put("ma", ion("foo::null.sexp"));
source.put("maa", ion("'com.foo.Bar'::null.sexp"));

IonValue data = ION_VALUE_MAPPER.readValue(ion, IonValue.class);
IonValue data = ION_VALUE_MAPPER.writeValueAsIonValue(source);
IonValueData result = ION_VALUE_MAPPER.readValue(data, IonValueData.class);

assertEquals(ion, data);
assertEquals(source, result);
}

@Test
public void shouldBeAbleToDeserializeAnnotatedIonNull() throws Exception {
IonValueData source = new IonValueData();
source.put("a", ion("foo::null"));
source.put("aa", ion("'com.foo.Bar'::null"));
source.put("b", ion("foo::null.null"));
source.put("ba", ion("'com.foo.Bar'::null.null"));

IonValue data = ION_VALUE_MAPPER.writeValueAsIonValue(source);
IonValueData result = ION_VALUE_MAPPER.readValue(data, IonValueData.class);

assertEquals(source, result);
}

@Test
public void shouldBeAbleToDeserializeUnannotatedIonNullToJavaNull() throws Exception {
IonValueData source = new IonValueData();
source.put("a", null);
source.put("b", ion("null"));
source.put("c", ion("null.null"));

IonValue data = ION_VALUE_MAPPER.writeValueAsIonValue(source);
IonValueData result = ION_VALUE_MAPPER.readValue(data, IonValueData.class);

IonValueData expected = new IonValueData();
expected.put("a", null);
expected.put("b", null);
expected.put("c", null);

assertEquals(expected, result);
}

@Test
Expand Down