Skip to content

Fix IonValueDeserializer's getNullValue when bean is missing a property #320

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
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 @@ -12,6 +12,7 @@ public class Fuzz_35979_StringValueTest extends CBORTestBase
{
private final ObjectMapper MAPPER = cborMapper();

// [dataformats-binary#316]
// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35979
public void testInvalidTextValueWithBrokenUTF8() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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

import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
Expand Down Expand Up @@ -58,11 +59,14 @@ 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) {
IonValue iv = (IonValue) embeddedObj;
if (iv.isNullValue()) {
return iv;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.fasterxml.jackson.dataformat.ion.ionvalue;

import com.amazon.ion.IonStruct;
import com.amazon.ion.IonSystem;
import com.amazon.ion.IonValue;
import com.amazon.ion.system.IonSystemBuilder;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.util.AccessPattern;
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper;
import java.io.IOException;
import org.junit.Test;

import java.util.HashMap;
Expand Down Expand Up @@ -172,6 +176,39 @@ public void shouldOverrideNullAccessPatternToBeDynamic() {
assertEquals(AccessPattern.DYNAMIC, deserializer.getNullAccessPattern());
}

static class MyBean {
public IonStruct required;
public IonStruct optional;

MyBean(
@JsonProperty("required") IonStruct required,
@JsonProperty("optional") IonStruct optional
) {
this.required = required;
this.optional = optional;
}
}

@Test
public void testWithMissingProperty() throws IOException
{
IonSystem ionSystem = IonSystemBuilder.standard().build();
IonObjectMapper ionObjectMapper = IonObjectMapper.builder(ionSystem)
.addModule(new IonValueModule())
.build();

String input1 = "{required:{}, optional:{}}";
MyBean deserializedBean1 = ionObjectMapper.readValue(input1, MyBean.class);
assertEquals(ionSystem.newEmptyStruct(), deserializedBean1.required);
assertEquals(ionSystem.newEmptyStruct(), deserializedBean1.optional);

// This deserialization should not fail with missing property
String input2 = "{required:{}}";
MyBean deserializedBean2 = ionObjectMapper.readValue(input2, MyBean.class);
assertEquals(null, deserializedBean2.optional);
assertEquals(ionSystem.newEmptyStruct(), deserializedBean2.required);
}

private static IonValue ion(String value) {
return SYSTEM.singleValue(value);
}
Expand Down