FasterXML / FasterXML/jackson-future-ideas
Deferred deserialization: Inject DeserializationContext into @JsonCreator methods
- Dominant language
- No language data
- Stars
- 21
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
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) {
// ...
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.