Subclass in a field with a concrete type is written, and then dropped on read
维护者通常 1 天内回复
@GarvSaxena 已经在做这个了。
开始于 2026年10月16日。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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!
- 主要语言
- Java
- 星标
- 4.6k
- 派生
- 470
- 平均合并
- 9 小时 28 分钟
- 30 天内合并 PR
- 33
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/fory 的其他 Issue
-
[Python] Compatible xlang read silently drops fields when the peer writes camelCase/PascalCase names未关闭
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
[Build] Add ASF license headers to config files that allow comments可能重新可做 @Swatantra-66 于 28 天前认领,目前没有进行中的 PR。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
xlang: the snake_case conversion of field names is not specified, and the runtimes do not agree可能重新可做 @dhruv-dagar 于 15 天前认领,目前没有进行中的 PR。 未关闭bug
难度 5/5 一周以上 新手友好度 25/100
维护者通常 1 天内回复
-
[Rust] Add an option to use Rust native enum可能已有人在做 @BaldDemian 于 20 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
apache/fory#4177 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Untyped read collapses a number literal that does not fit a double可能已有人在做 @mohitjoshi-hey 于 21 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 68/100
apache/fory#4170 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
objectionary/lints#1640 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 半天 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
openhab/openhab-addons#22168 ·
维护者通常 1 天内回复