Subclass in a field with a concrete type is written, and then dropped on read
Maintainer thường phản hồi trong vòng 1 ngày
@GarvSaxena đang làm issue này rồi.
Từ ngày 16/10/2026.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 50/100
Hướng nghiên cứu
Start with the Java JSON serialization and deserialization paths exercised by the provided ForyJson example, then compare their handling of a concrete declared field whose runtime value is a subclass with the binary module’s behavior. Reproduce the example and trace how the JSON reader chooses the field type. Done means it either preserves the subclass and its breed field or reports clearly that writing would discard subclass data.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Search before asking
- I had searched in the issues and found no similar issues.
Version
1.7.7
Component(s)
Java
Minimal reproduce step
A field has a declared type. The declared type is a concrete class, and the class is not final. The value is an instance of a subclass.
Version 1.7.7 writes the fields of the subclass, which 1.7.6 did not. The read operation still builds the declared type and ignores those fields. The data is therefore in the document, and nothing can read it. Fory gives no error at either step.
import org.apache.fory.Fory;
import org.apache.fory.config.Language;
import org.apache.fory.json.ForyJson;
public class SubclassStateDropped {
public static class Animal {
String name = "generic";
public String toString() { return "Animal(name=" + name + ")"; }
}
public static class Dog extends Animal {
String breed = "lab";
public Dog() { name = "rex"; }
public String toString() { return "Dog(name=" + name + ", breed=" + breed + ")"; }
}
public static class Owner {
private Animal pet = new Dog();
public Owner() { }
public String toString() { return "Owner(pet=" + pet + ")"; }
}
public static void main(String[] args) {
Owner original = new Owner();
ForyJson json = ForyJson.builder().withFieldMode(true).build();
byte[] doc = json.toJsonBytes(original);
System.out.println("fory-json wrote : " + new String(doc));
System.out.println("fory-json read : " + json.fromJson(doc, Owner.class));
Fory core = Fory.builder().withLanguage(Language.JAVA).requireClassRegistration(false).build();
System.out.println("fory-core read : " + core.deserialize(core.serialize(original)));
}
}
What did you expect to see?
One of two results.
In the first result, fory-json reads the document it wrote and gives Owner(pet=Dog(name=rex, breed=lab)). The binary module gives this result for the same object, as the third line of the output shows, so it is the behaviour the project has already established.
In the second result, fory-json refuses the write operation. The error message tells the user that the runtime type is a subtype of the declared type, and that a write operation discards data.
Fory JSON has no open polymorphism, and we know that this is a design decision. That makes the second result the one we expected. In both results the application can find that Fory made a decision.
What did you see instead?
Owner(pet=Animal(name=rex)), and no error from either step.
The document holds "breed":"lab". The value of name is "rex", which the constructor of Dog assigns, so the object written was the Dog. The read operation builds an Animal and ignores breed. No part of the API tells the application that the field was discarded.
Anything Else?
No response
Are you willing to submit a PR?
- I'm willing to submit a PR!
- Ngôn ngữ chính
- Java
- Star
- 4.6k
- Fork
- 470
- Merge trung bình
- 9 giờ 28 phút
- Pull request đã merge (30 ngày)
- 33
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/fory
-
[Python] Compatible xlang read silently drops fields when the peer writes camelCase/PascalCase namesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Build] Add ASF license headers to config files that allow commentsCó thể làm lại được @Swatantra-66 đã nhận 27 ngày trước và không có pull request nào đang mở. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/fory#4124 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
xlang: the snake_case conversion of field names is not specified, and the runtimes do not agreeCó thể làm lại được @dhruv-dagar đã nhận 15 ngày trước và không có pull request nào đang mở. Đang mởbug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
apache/fory#4187 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Rust] Add an option to use Rust native enumCó thể đã có người làm @BaldDemian đã nhận 19 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
apache/fory#4177 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Untyped read collapses a number literal that does not fit a doubleCó thể đã có người làm @mohitjoshi-hey đã nhận 21 ngày trước. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
apache/fory#4170 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
a2aproject/a2a-java#1275 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
module/ftp Type/Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ballerina-platform/ballerina-library#9476 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
anwilli5/coin-collection-android-US#515 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status: waiting-for-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
spring-projects/spring-integration#11654 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 70/100
Vakore/ZappierGames#248 ·