Subclass in a field with a concrete type is written, and then dropped on read
I maintainer di solito rispondono entro 1 giorno
@GarvSaxena ci sta già lavorando.
Dal 16/10/2026.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 50/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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!
- Lingua principale
- Java
- Stelle
- 4.6k
- Fork
- 470
- Merge medio
- 9h 28m
- PR unite (30g)
- 33
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/fory
-
[Python] Compatible xlang read silently drops fields when the peer writes camelCase/PascalCase namesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
[Build] Add ASF license headers to config files that allow commentsForse di nuovo libera @Swatantra-66 l’ha presa 29 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/fory#4124 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
xlang: the snake_case conversion of field names is not specified, and the runtimes do not agreeForse di nuovo libera @dhruv-dagar l’ha presa 16 giorni fa e non c’è nessuna pull request aperta. Apertabug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
apache/fory#4187 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Rust] Add an option to use Rust native enumForse già presa @BaldDemian l’ha presa 21 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
apache/fory#4177 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Untyped read collapses a number literal that does not fit a doubleForse già presa @mohitjoshi-hey l’ha presa 23 giorni fa. Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
apache/fory#4170 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
wpilibsuite/SystemcoreTesting#446 ·
I maintainer di solito rispondono entro 1 giorno
-
frontend quality-assurance
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
Paul-Austin-Oswego-CSC480-HCI521/gift-app#212 ·
I maintainer di solito rispondono entro 1 giorno
-
Mend: dependency security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Docs: AGENTS.md agent/ module-map bullet missing AgentWriteRules — the deny-by-default write gateApertadocumentation hermes-queue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
chrisalunlloyd2-sudo/mindpalace#334 ·
I maintainer di solito rispondono entro 1 giorno
-
needs-area-label
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 2 giorni