FasterXML / FasterXML/jackson-dataformats-binary

[Ion] Embedded value lost when deserializing with @JsonTypeInfo

Aberta
#152 0 comentários 0 reações 0 responsáveis Ver no GitHub
ion
Linguagem predominante
Java
Estrelas
347
Forks
156
Merge médio
3d 3h
PRs com merge (30d)
22

Descrição

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

```

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.