Support simpler and easier streaming parsing for nested objects
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 20/100
Research direction
This is a design-level feature request for lazy/streaming deserialization of nested collections in jackson-databind. Start by reading the linked issue #1304 and the maintainer discussion in the comments, then explore how ObjectReader and the deserializer for collection types currently bind the whole payload. Several alternative APIs (Iterable/Stream wrappers, annotations, callbacks) are proposed without a decision, so 'done' first means an agreed design with maintainers, not a patch.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
When integrating with some third-party APIs, there is sometimes a very large amount of data, and the relatively large data is inside an object, so there is no simple and easy way to parse it in a streaming manner.
{
"code": 200,
"message": "xxx",
"data": [
{
"id": 1,
"name": "xxx",
"age": 18
},
{
"id": 2,
"name": "xxx",
"age": 18
}
// ... a lot json data
]
}
But I have no way to ask the API provider to change the structure, so I would like to support this kind of nested streaming parsing.
Describe the solution you'd like
I want to use something like the following:
import lombok.Data;
@Data
public class ListUserInfoResponse {
private Integer code;
private String message;
private Iterable<Data> data;
@lombok.Data
public static class Data {
private Integer id;
private String name;
private Integer age;
}
}
ListUserInfoResponse can be loaded normally, but the data inside it is loaded in a streaming and lazy manner.
It does not have to use Iterable; it could also be wrapped in Jackson's own data class (preferably one that implements Iterable or Stream).
Alternatively, directly supporting Iterable or Stream is also possible, but it may be difficult to adapt, which is why Jackson's own data class may be needed.
Or it could be done by using an annotation on this class field.
However, this approach may not be friendly to things like InputStream that need to be closed, since it is lazy-loaded and may be closed midway.
So my idea is to first read the entire InputStream completely, and automatically convert it to ListUserInfoResponse.
When a property of a specific type or marked with a specific annotation is encountered, convert it to an Iterable or Stream implemented by Jackson's own implementation class, which stores the partial string read from the InputStream, that is, the string for this property.
Only when this property is iterated over does parsing begin according to the type. Personally, I feel Iterable is indeed better; for iterable data of unknown size, it is indeed more appropriate than data types like List whose size is known.
Alternatively, use a callback function for things like InputStream that need to be closed, and automatically close it after the callback finishes (but this seems not very friendly to imperative blocking operations).
Usage example
No response
Additional context
Personally, I think that although the entire string also occupies a large amount of memory, and directly using low-level operations to read may occupy less memory, I think this solution is better in terms of convenience and ease of use, and it also saves more memory than the approach without streaming lazy loading. It is a relatively good compromise.
For small amounts of data, just load it directly; for very large datasets, use low-level operations to read; if it is relatively large and you also want to reduce memory usage, I think this solution is better.
https://github.com/FasterXML/jackson-databind/issues/1304
https://juneau.staged.apache.org/docs/topics/LargeDatasetStreaming/#in-memory-listbeanchannel
- 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