FasterXML / FasterXML/jackson-dataformats-binary

[Ion] Embedded value lost when deserializing with @JsonTypeInfo

Đang mở
#152 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
ion
Ngôn ngữ chính
Java
Star
347
Fork
156
Merge trung bình
3 ngày 3 giờ
Pull request đã merge (30 ngày)
22

Mô tả

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

```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.