Support conditional type ID inclusion during deserialization
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- java
- Domain
- backend, performance
Research direction
Start with AsPropertyTypeDeserializer, especially _deserializeTypedForId and the referenced lines 131-143, then review JsonTypeInfo.visible and the public AsPropertyTypeDeserializer or StdTypeResolverBuilder APIs. Reproduce the supplied performance test and verify that default implementations can receive the type while non-default deserializers avoid the unnecessary intermediate allocations.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
When a default implementation is used on a polymorphic @JsonTypeInfo the visible = true attribute needs to be set for that default implementation to know the missing type. However for the non-default cases usually the type is known ahead of time, and making the type property visible to the concrete deserializer adds significant allocation cost for the intermediate TokenBuffer.
Specifically, this code snippet allocates a token buffer (with a 16 element segment), the associated TokenBuffer$Parser, and JsonParserSequence.
Describe the solution you'd like
Ideally, adding a third option to the JsonTypeInfo.visible field that indicates "visible only to the default implementation", but this is likely fairly complicated due to the field currently being a boolean.
Alternatively, perhaps adding an optimized JsonParser subtype like PrependedTypeProperty(String typeField, String typeId, JsonParser delegate) that avoids the majority of the allocations.
Currently, we're using our own subtype of AsPropertyTypeDeserializer that overrides _deserializeTypedForId that overrides if (_typeIdVisible) { to instead check if (deserializer == _defaultImplDeserializer) { in a few targeted places we've observed this performance issue, but this is not ideal because those are internal APIs. If modifying @JsonTypeInfo is too high lift, perhaps adding the option to the public API of AsPropertyTypeDeserializer or StdTypeResolverBuilder would be an alternative.
Performance Test
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type",
visible = true,
defaultImpl = Default.class)
@JsonSubTypes(@JsonSubTypes.Type(value = Concrete.class, name = "concrete"))
private interface Base {}
private record Default(String type) implements Base {}
@JsonTypeName("concrete")
@JsonPropertyOrder({"type", "content"})
private static final class Concrete implements Base {
@JsonProperty("type")
public String type() {
return "concrete";
}
@JsonProperty("content")
public int content;
}
public static void main(String[] args) throws IOException {
ObjectMapper objectMapper =
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Concrete obj = new Concrete();
obj.content = 12345;
byte[] bytes = objectMapper.writeValueAsBytes(
IntStream.range(0, 1000).mapToObj(_x -> obj).toList());
TypeReference<List<Base>> type = new TypeReference<>() {};
for (int i = 0; i < 10_000; i++) {
objectMapper.readValue(bytes, type);
}
}
Additional context
No response
- Dominant language
- Java
- Stars
- 3.8k
- Forks
- 1.6k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 59
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from FasterXML/jackson-databind
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
FasterXML/jackson-databind#6443 ·
Maintainers usually reply within 1 day
-
to-evaluate
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
FasterXML/jackson-databind#6340 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 12/100
FasterXML/jackson-databind#6442 ·
Maintainers usually reply within 1 day
-
`@JsonUnwrapped` value with `EXTERNAL_PROPERTY` type id silently deserialized as `null` (or misleading unknown-property error)Possibly taken @wn1331 claimed this 2 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
FasterXML/jackson-databind#6421 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 1-2 days Newbie friendliness 35/100
FasterXML/jackson-databind#6418 · 2 comments ·
Maintainers usually reply within 1 day
All issues in FasterXML/jackson-databind
Similar issues
-
Cleanup: restore the interrupt flag in AiFailureAnalyzerPossibly taken @Rishankgupta08 claimed this today. Opengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
seleniumboot/selenium-boot#258 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dense-analysis/ale#5181 ·
-
bug subsystem:agent-harness triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ShaftHQ/SHAFT_ENGINE#8043 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
johanhaleby/occurrent#1505 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day