FasterXML / FasterXML/jackson-dataformats-binary

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

Ouverte
#112 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
ion
Langage dominant
Java
Étoiles
347
Forks
156
Merge moyen
3 j 3 h
PR mergées (30 j)
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());
}
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.