FasterXML / FasterXML/jackson-future-ideas

Deferred deserialization: Inject DeserializationContext into @JsonCreator methods

Ouverte
#16 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Aucune donnée de langage
Étoiles
21
Forks
3
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I have a few use cases where JSON deserialization may be _deferred_, and the user given a chance to override, modify properties, merge with another bean, or otherwise defer deserialization until some later point in runtime. Right now, there doesn't seem to be a feasible way to do this other than to write a weighty `JsonDeserializer` implementation that detects the value type, constructs the content deserializer, etc.

Instead, it would be wonderful if an annotation allowed for injection of a `SubDeserializer`, with nothing but:

- `T deserialize(JsonParser parser) throws IOException`
- `SubDeserializer with/without(DeserializationFeature... features)`

independently callable at a later time. This allows something like:

```java
public class JsonTemplate {
private final JsonNode json;
private final SubDeserializer deserializer;

@JsonCreator
public JsonTemplate(JsonNode json, SubDeserializer deserializer) {
this.json = json;
this.deserializer = deserializer;
}

public T render(StrSubstitutor substitutor) throws JsonProcessingException {
JsonNode substitutedJson = substitute(json, substitutor);
try {
return deserializer.deserialize(new TreeTraversingParser(substitutedJson));
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) {
throw new RuntimeException(e); // nope
}
}

private static JsonNode substitute(JsonNode json, StrSubstitutor substitutor) {
// ...
}
}
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.