FasterXML / FasterXML/jackson-databind
Location incorrectly reported when using `@JsonTypeInfo`
- Lingua principale
- Java
- Stelle
- 3.7k
- Fork
- 1.5k
- Merge medio
- 3g 6h
- PR unite (30g)
- 28
Descrizione
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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.