FasterXML / FasterXML/jackson-dataformats-binary

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

未关闭
#112 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
ion
主要语言
Java
星标
347
派生
156
平均合并
3 天 3 小时
30 天内合并 PR
22

描述

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());
}
```

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。