jakartaee / jakartaee/jsonb-api
Simple way to 'flatten' ?
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
I have an Employee class that produces the following JSON:
```javascript
{
"audit": {
"createdDate": "2019-03-17T21:07:57.019",
"updatedDate": "2019-03-17T21:07:57.019"
},
"id": 1,
"version": 1,
"firstName": "Mike",
"lastName": "Norman",
"salary": 5000
}
```
The `audit` element is from the JPA Embeddable class `Audit` which contains timestamp info for when the object is created and updated in the database
```java
@Embeddable
public class Audit {
protected LocalDateTime createdDate;
protected LocalDateTime updatedDate;
public Audit() {
}
@Column(name = "CREATED_DATE")
public LocalDateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(LocalDateTime createdDate) {
this.createdDate = createdDate;
}
@Column(name = "UPDATED_DATE")
public LocalDateTime getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(LocalDateTime updatedDate) {
this.updatedDate = updatedDate;
}
}
```
I would like to 'flatten' the audit portion of the JSON:
```javascript
{
"createdDate": "2019-03-17T21:07:57.019",
"updatedDate": "2019-03-17T21:07:57.019"
"id": 1,
"version": 1,
"firstName": "Mike",
"lastName": "Norman",
"salary": 5000
}
```
I have started down the road of `JsonbSerializer` but things are getting pretty complicated pretty quick. Is there a simpler way to accomplish this?
I know that Jackson had the `@JsonUnwrapped` annotation which seems wonderful right now ;-)
Contributor guide
Research direction
Start by reviewing the JsonbSerializer entry point and the JSON-B serialization behavior described in the examples. Determine whether an embeddable Audit object can expose createdDate and updatedDate at the containing object's top level without custom serializer complexity. Done means the requested flattened JSON shape is supported and covered by the project's relevant tests.
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