FasterXML / FasterXML/jackson-databind

Location incorrectly reported when using `@JsonTypeInfo`

Ouverte
#2,386 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
polymorphic-handling
Langage dominant
Java
Étoiles
3.7k
Forks
1.5k
Merge moyen
3 j 6 h
PR mergées (30 j)
28

Description

I have the following interface:

```
@JsonTypeInfo(
use=JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "id"
)
@JsonSubTypes({
@Type (value = ChildA.class, name="A"),
@Type (value = ChildB.class, name="B")
})
public interface Parent {

public int getValue();

public void setValue(int value);
}
```

`ChildA` and `ChildB` are classes which implement `Parent` and only contain an empty constructor and the obvious getter/setter implementations.

Now, I have the following JSON:

```
{
"Foo": "Bar",
"value": 5,
"id": "A",
}
```

If I deserialize this JSON (using `mapper.readValue(json, Parent.class)`), then I get an exception (which is expected):
```
Unrecognized field "Foo" (class testJacksonParseError.ChildA), not marked as ignorable (one known property: "value"])
at [Source: (File); line: 4, column: 11] (through reference chain: testJacksonParseError.ChildA["Foo"])
```
What's unexpected is the reported location. The exception incorrectly returns line 4 when the unrecognized property is actually on line 2. If I change the `id` field to be the first line of the JSON object, then the location is reported correctly again. Similarly, expanding the object to contain more data, it seems that any parse errors occurring before the `id` field are always incorrectly reported as occurring at the location of the `id` field. So, I'm guessing there's a bug in how the location is gathered when deserializing into a class with the `@JsonTypeInfo` annotation.

I'm using Jackson 2.9.8.

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.