FasterXML / FasterXML/jackson-dataformats-binary

[Ion] Incorrect IonValue deserialization for wrapper/value classes - IonStructs not handled correctly

Open
#112 1 comment 0 reactions 0 assignees View on GitHub
ion
Dominant language
Java
Stars
347
Forks
156
Avg merge
3d 3h
Merged PRs (30d)
22

Description

Ran into a strange issue with deserializing wrapper/value classes when the content of the IonValue is suppose to be a struct. Some test cases are below. The issue is shown at the bottom of the test below: `mapper.readValue("{ a: b }", TestValueType.class);`. This gets read as an ion symbol 'b' instead of an ion struct { a: b } and I believe it's because of the [code here](https://github.com/FasterXML/jackson-databind/blob/2.9/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java#L153-L155) that steps into the struct before yielding to the deserializer?

Not sure if this is the correct analysis or what the proper course of action should be if it is correct. Any ideas?

```java
public static class TestValueType {

private IonValue value;

private TestValueType(IonValue value) {
this.value = value;
}

@JsonCreator
public static TestValueType of(IonValue value) {
return new TestValueType(value);
}

@JsonValue
public IonValue getValue() {
return value;
}
}

@Test
public void deserializeValueType() throws IOException {
IonSystem ionSystem = IonSystemBuilder.standard().build();

IonObjectMapper mapper = new IonObjectMapper();
mapper.registerModule(new IonValueModule());
TestValueType testType;

testType = mapper.readValue("a_symbol", TestValueType.class);
assertEquals(ionSystem.newSymbol("a_symbol"), testType.getValue());

testType = mapper.readValue("\"a_string\"", TestValueType.class);
assertEquals(ionSystem.newString("a_string"), testType.getValue());

testType = mapper.readValue("1.0", TestValueType.class);
assertEquals(ionSystem.newDecimal(1.0), testType.getValue());

testType = mapper.readValue("1", TestValueType.class);
assertEquals(ionSystem.newInt(1), testType.getValue());

testType = mapper.readValue("1.0e0", TestValueType.class);
assertEquals(ionSystem.newFloat(1.0), testType.getValue());

testType = mapper.readValue("[1, 2]", TestValueType.class);
IonList expectedList = (IonList) ionSystem.singleValue("[1, 2]");
assertEquals(expectedList, testType.getValue());

testType = mapper.readValue("(a b)", TestValueType.class);
IonSexp expectedSexp = (IonSexp) ionSystem.singleValue("(a b)");
assertEquals(expectedSexp, testType.getValue());

testType = mapper.readValue("{ a: b }", TestValueType.class);

//Should be this
//IonStruct expectedStruct = (IonStruct) ionSystem.singleValue("{ a: b }");
//assertEquals(expectedStruct, testType.getValue());

//Unfortunately, it's this
IonSymbol actualValue = (IonSymbol) ionSystem.singleValue("b");
assertEquals(actualValue, testType.getValue());
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.