jakartaee / jakartaee/jsonb-api
Partial serialization/deserialization
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
There are cases when deserialization is getting complex. For example, if the value of one property decides about how to proceed with other attributes, as it could happen with polymorphic hierarchies:
```json
{
"kind": "com.my.ClassName",
"foo": "x",
"bar": "y"
}
```
In this example, the class name is *not* found in a surrounding wrapper, but directly in the *same* object's `kind` propery (e. g. Kubernetes API does this style). Currently such a deserializer needs to handle not only "kind" using JSON-P, but *also* `foo` and `bar`. That's not nice. It would be better if the deserializer could simply do this:
```java
Class c = parseKind(parser); // uses JSON-P to turn "kind" into "Class"
Object o = c.newInstance();
deserializationContext.deserialize(o, parser); // has no return type but writes into "o" from "here" until END_OBJECT
```
This simply will deserialize into the existing object "o" from the parser's current position. It is working just like the existing `deserialize(Class, JsonParser)` but does *not* create an new instance nor returning it, and it does not expect an opening bracket `{`.
On the serialization side, it would be great to have an analog solution, e. g. `SerializationContext.serialize(T object, JsonGenerator generator, boolean omitStartingBracket)` which works like the existing variant, but just does not write the starting bracket in case 'false' is provided.
Contributor guide
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.
Research direction
Start by reviewing the existing deserialize(Class, JsonParser) and SerializationContext serialization variants mentioned in the issue, along with the JSON-P parser and generator usage. Clarify the API and boolean semantics for continuing from the current parser position and omitting an opening bracket, then define tests showing partial object deserialization and serialization behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100