FasterXML / FasterXML/jackson-databind

Deduction deserialization - add support for pojo-hierarchies such that the absence of child fields infers a supertype

Đang mở
#3,289 20 bình luận 1 reaction 0 người được giao Xem trên GitHub
polymorphic-deduction
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ả

Currently, deduction deserialization requires all values to have unique field. Because of that, there is no way to deserialize values to superclass and subclasses, when `defaultImpl` is different than superclass.

Example:

For json:
```{
"name": "Italy",
"places": {
"mountains": {
"name": "The Alps"
},
"cites": [
{
"name": "Rome",
"places": {
"colosseum": {
"name": "The Colosseum"
},
"romanForum": {
"name": "The Roman Forum"
}
}
},
{
"name": "Venice",
"places": {
"bridges": []
}
}
]
}
}
```

and pojo-hierarchy:

```
public static class Place implements WorthSeeing {
public String name;
}

public static class CompositePlace extends Place implements WorthSeeing {

public Map places;
}

static class ListOfPlaces extends ArrayList implements WorthSeeing {
}
```

and deduction deserialization with `defaultImpl` differ then supertype:

```
@JsonTypeInfo(use = DEDUCTION, defaultImpl = ListOfPlaces.class)
@JsonSubTypes( {@Type(ListOfPlaces.class), @Type(CompositePlace.class), @Type(Place.class)})
interface WorthSeeing {}
```

the `MismatchedInputException` is thrown, because the values with only `name` fields are not classified to `Place` .

Desired behaviour:
- value contains only fields from superclass -> it's mapped to an object of superclass
- value contains fields from superclass and a subclass -> it's mapped to an object of the supclass
- value contains fields from superclass and fields that don't exist in any of subclasses -> the `UnrecognizedPropertyException` is thrown

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.