FasterXML / FasterXML/jackson-databind

Location incorrectly reported when using `@JsonTypeInfo`

Đang mở
#2,386 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
polymorphic-handling
Ngôn ngữ chính
Java
Star
3.7k
Fork
1.5k
Merge trung bình
3 ngày 6 giờ
Pull request đã merge (30 ngày)
28

Mô tả

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.

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.