FasterXML / FasterXML/jackson-dataformats-binary
[Ion] Embedded value lost when deserializing with @JsonTypeInfo
- 主要语言
- Java
- 星标
- 347
- 派生
- 156
- 平均合并
- 3 天 3 小时
- 30 天内合并 PR
- 22
描述
I found an issue when trying to deserialize an IonValue embedded in a pojo. The conditons I've found that are required to hit it:
1. Must be deserializing to Ion
2. Must have `@JsonTypeInfo` annotation on the class (or on a super class) that specifies the type in a property.
3. The type attribute must come after other attributes of the struct. Anything before the type attribute will be lost during deserialization.
When I've walked through this with a debugger, I found something suspicious happening at [this line](https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java#L125). I found it was creating a sequence of a json and ion parser and started using the json parser once the type was identified.
This may be related to https://github.com/FasterXML/jackson-dataformats-binary/issues/149 .
Code to reproduce:
```java
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import software.amazon.ion.IonSystem;
import software.amazon.ion.IonValue;
import com.fasterxml.jackson.dataformat.ion.ionvalue.IonValueMapper;
import software.amazon.ion.system.IonSystemBuilder;
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type")
public class Main {
private IonValue value;
@JsonCreator
public Main(@JsonProperty("value") IonValue value) {
this.value = value;
}
public IonValue getValue() {
return value;
}
public static void main(String[] args) throws Exception{
IonSystem system = IonSystemBuilder.standard().build();
IonValueMapper mapper = new IonValueMapper(system);
Main main = mapper.parse(system.singleValue("{value:4.0, type: \"Main\"}"), Main.class);
System.out.println("newMain value: " + main.getValue()); // prints null, but should be 4.0.
}
}
```
Tested with the following dependencies:
```xml
com.fasterxml.jackson.dataformat
jackson-dataformat-ion
2.9.7
software.amazon.ion
ion-java
1.2.0
com.fasterxml.jackson.core
jackson-core
2.9.7
com.fasterxml.jackson.core
jackson-databind
2.9.7
com.fasterxml.jackson.core
jackson-annotations
2.9.7
```
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。