`Optional<JsonNode>` deserialization from "absent" value does not work in the expected way
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 50/100
Direzione di ricerca
Inizia in jackson-datatype-jdk8 OptionalDeserializer e segui la gestione delle proprietà mancanti attraverso PropertyValueBuffer::_findMissing, JsonDeserializer#getAbsentValue e JsonNodeDeserializer#getNullValue. Conferma il comportamento dell’esempio MyRecord deserializzato da {} e assicurati che l’Optional assente rimanga vuoto invece di contenere un NullNode; verifica il risultato atteso con i test esistenti del progetto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Example:
public record MyRecord(
Optional<JsonNode> myField
) {
}
When deserialized from: {}
Expected:
myField.isPresent() == false
Actual:
myField.isPresent() == true
This is because myField gets set to an Optional of a NullNode
After spending some time looking into the source code of both the jackson-databind and the jackson-datatype-jdk8 libraries, the problem seems to lie in the OptionalDeserializer (or higher).
During deserialization, when a property is missing, the PropertyValueBuffer::_findMissing method is called and in it, this piece of code is called:
https://github.com/FasterXML/jackson-databind/blob/0fe97e0d69b7d5362907b094d5b979bc2216dc4a/src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyValueBuffer.java#L203
// Third: NullValueProvider? (22-Sep-2019, [databind#2458])
// 08-Aug-2021, tatu: consider [databind#3214]; not null but "absent" value...
Object absentValue = prop.getNullValueProvider().getAbsentValue(_context);
if (absentValue != null) {
return absentValue;
}
The OptionalDeserializer is not overriding its inherited getAbsentValue method to return Optional.ofNullable(_valueDeserializer.getAbsentValue(ctxt)); (or similar).
Due to the lack of the overriding, the inherited getAbsentValue method actually calls getNullValue instead as can be seen here:
https://github.com/FasterXML/jackson-databind/blob/0fe97e0d69b7d5362907b094d5b979bc2216dc4a/src/main/java/com/fasterxml/jackson/databind/JsonDeserializer.java#L349
@Override
public Object getAbsentValue(DeserializationContext ctxt) throws JsonMappingException {
return getNullValue(ctxt);
}
In the case of a JsonNode, the JsonNodeDeserializer is used. This deserializer overrides the getNullValue method to return a NullNode.
@Override
public JsonNode getNullValue(DeserializationContext ctxt) {
return ctxt.getNodeFactory().nullNode();
}
- Lingua principale
- Java
- Stelle
- 425
- Fork
- 125
- Merge medio
- 19m
- PR unite (30g)
- 1
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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 FasterXML/jackson-modules-java8
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
-
Wrap `DateTimeException` Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
FasterXML/jackson-modules-java8#382 · 3 commenti ·
-
date-time-config
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
FasterXML/jackson-modules-java8#374 · 31 commenti · 1 reazione ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
FasterXML/jackson-modules-java8#310 · 1 commento ·
-
Instants get not deserialized as expected sometimes (millis vs nanos, non-fractional numbers) Apertatest-needed
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
FasterXML/jackson-modules-java8#304 · 3 commenti ·
Tutte le issue di FasterXML/jackson-modules-java8
Issue simili
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
apache/flink-agents#1152 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
jenkinsci/blueocean-plugin#5417 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
objectionary/eo-graphs#75 ·