Subclass in a field with a concrete type is written, and then dropped on read
Los mantenedores suelen responder en 1 día
@GarvSaxena ya está trabajando en esto.
Desde el 16/10/2026.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 50/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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!
- Lenguaje dominante
- Java
- Estrellas
- 4.6k
- Forks
- 470
- Merge medio
- 9 h 28 min
- PR fusionados (30 d)
- 33
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/fory
-
[Python] Compatible xlang read silently drops fields when the peer writes camelCase/PascalCase namesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
[Build] Add ASF license headers to config files that allow commentsQuizá libre de nuevo @Swatantra-66 la tomó hace 29 días y no hay ningún pull request abierto. Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/fory#4124 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
xlang: the snake_case conversion of field names is not specified, and the runtimes do not agreeQuizá libre de nuevo @dhruv-dagar la tomó hace 17 días y no hay ningún pull request abierto. Abiertobug
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
apache/fory#4187 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Rust] Add an option to use Rust native enumPosiblemente ocupada @BaldDemian la tomó hace 21 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
apache/fory#4177 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Untyped read collapses a number literal that does not fit a doublePosiblemente ocupada @mohitjoshi-hey la tomó hace 23 días. Abiertobug
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
apache/fory#4170 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de apache/fory
Issues similares
-
Type: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
MCP add-on: JSON responses with non-ASCII characters are truncated (wrong Content-Length)Posiblemente ocupada @dhanushbs10 la tomó hoy. Abiertoadd-on bug in:mcp
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
vaadin-map
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
vaadin/flow-components#10586 ·
Los mantenedores suelen responder en 1 día
-
WeReadInstaller writes the launcher database on the main thread at handover (Activity pause timeout)Abiertobug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
wpilibsuite/SystemcoreTesting#446 ·
Los mantenedores suelen responder en 1 día