Registered factory cannot tell a field from the root of the call
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start at ModuleContext.registerCodecFactory and trace how Fory invokes and caches codec factory answers during root serialization, field serialization, and deserialization. Use the four cases in the reproducer to check whether the factory can distinguish a root value from a field; done means the position is identifiable and the expected behavior is covered by tests. The issue does not name test or implementation files.
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
ModuleContext.registerCodecFactory is the correct method for an application to supply a codec. It
would also let an application work around https://github.com/apache/fory/issues/4168: a factory that claims the concrete declared
type could write and read the subclass itself.
It cannot do that. Fory asks the factory about the class at the root of its own call and about a field
of that class, and the two questions are not different. Fory also caches the answer for each type, so
the first answer is permanent.
import org.apache.fory.json.*;
import org.apache.fory.json.codec.JsonValueCodec;
import org.apache.fory.json.reader.*;
import org.apache.fory.json.resolver.JsonTypeResolver;
import org.apache.fory.json.writer.*;
import org.apache.fory.reflect.TypeRef;
import java.util.ArrayList;
import java.util.List;
public class RootAndFieldAlike {
public static class Pet { public String name = "rex"; public Pet() { } }
public static class Owner { public Pet pet = new Pet(); public Owner() { } }
static List<String> questions = new ArrayList<>();
/** a new instance each time, so a cached codec cannot hide a question */
static ForyJson fresh() {
questions = new ArrayList<>();
ForyJsonModule module = ctx -> ctx.registerCodecFactory(
(TypeRef<?> type, JsonTypeResolver resolver, boolean runtimeType) -> {
if (type.getRawType() == Pet.class) {
questions.add("Pet, runtimeType=" + runtimeType);
}
return null;
});
return ForyJson.builder().withFieldMode(true).withModule(module).build();
}
public static void main(String[] args) {
ForyJson a = fresh();
a.toJsonBytes(new Owner());
print("a Pet held by a field of Owner", questions);
ForyJson b = fresh();
b.toJsonBytes(new Pet());
print("a Pet as the root of the call", questions);
ForyJson c = fresh();
c.fromJson("{\"pet\":{\"name\":\"rex\"}}".getBytes(), Owner.class);
print("reading a Pet held by a field", questions);
ForyJson d = fresh();
d.fromJson("{\"name\":\"rex\"}".getBytes(), Pet.class);
print("reading a Pet as the root", questions);
}
static void print(String what, List<String> asked) {
System.out.println(what + ":");
if (asked.isEmpty()) {
System.out.println(" never asked");
return;
}
for (String q : asked) {
System.out.println(" " + q);
}
}
}
What did you expect to see?
A question that says which of the two positions the type is in. The runtimeType flag looks like that
question, so we expected true for the root of the call and false for a field.
What did you see instead?
runtimeType=false for a field and for the root. The root is asked twice, once with each value, so
no value of the flag means "this is a field".
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