jakartaee / jakartaee/jsonb-api
Enhance "Jsonb" to allow "fromJson" to handle "JsonStructure" as input
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
Hey there,
It would be nice to enhance the interface [javax.json.bind.Jsonb](https://github.com/eclipse-ee4j/jsonb-api/blob/master/api/src/main/java/javax/json/bind/Jsonb.java) to allow handling of [javax.json.JsonStructure](https://github.com/eclipse-ee4j/jsonp/blob/master/api/src/main/java/javax/json/JsonStructure.java) as input for deserialization (unmarshalling to a Java class).
This means, there should be two new methods :
```java
public interface Jsonb extends AutoCloseable {
...
T fromJson(JsonStructure jsonStruct, Class type) throws JsonbException;
T fromJson(JsonStructure jsonStruct, Type runtimeType) throws JsonbException;
}
```
Yasson already supports this for the opposite direction (serialization):
```java
JsonObject jsonObj = Json.createObjectBuilder().add("name", "Peter Parker").add("age", 18).build();
Jsonb jsonb = JsonbBuilder.create();
System.out.println(jsonb.toJson(jsonObj));
// Prints {"name":"Peter Parker","age":18}
```
But currently JSON-B does not support deserialization like:
```java
Person person = jsonb.fromJson(jsonObj, Person.class);
```
Unfortunately this is a breaking change, but it could be implemented in the interface with a default method that throws an "UnsupportedOperationException" in case the provider does not implement it.
What do you think?
Cheers,
Michael
Contributor guide
Research direction
Start with api/src/main/java/javax/json/bind/Jsonb.java and review the existing fromJson overloads and the compatibility concerns raised in the issue. Confirm how JsonStructure input should be deserialized and whether provider behavior needs corresponding API coverage; done means the proposed overloads are defined with the requested signatures and their expected behavior is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100