-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We need more control over what is provided by the caller
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
dina-json/src/main/java/ca/gc/aafc/dina/jsonapi/JsonApiDocument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package ca.gc.aafc.dina.jsonapi; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Jacksonized | ||
@Builder | ||
@Getter | ||
public class JsonApiDocument { | ||
|
||
private ResourceObject data; | ||
|
||
public UUID getId() { | ||
return data != null ? data.getId() : null; | ||
} | ||
|
||
public Map<String, Object> getAttributes() { | ||
return data != null ? data.getAttributes() : null; | ||
} | ||
|
||
public Map<String, RelationshipObject> getRelationships() { | ||
return data != null ? data.getRelationships() : null; | ||
} | ||
|
||
/** | ||
* Defines a single-resource object as per <a href="https://jsonapi.org/format/#document-resource-objects">...</a> | ||
*/ | ||
@Jacksonized | ||
@Builder | ||
@Getter | ||
public static class ResourceObject { | ||
private String type; | ||
private UUID id; | ||
|
||
private Map<String, Object> attributes; | ||
|
||
private Map<String, RelationshipObject> relationships; | ||
|
||
public Set<String> getAttributesName() { | ||
return attributes != null ? attributes.keySet() : Set.of(); | ||
} | ||
|
||
public Set<String> getRelationshipsName() { | ||
return relationships != null ? relationships.keySet() : Set.of(); | ||
} | ||
} | ||
|
||
/** | ||
* Defines a relationship object as per <a href="https://jsonapi.org/format/#document-resource-object-relationships">...</a> | ||
*/ | ||
@Jacksonized | ||
@Builder | ||
@Getter | ||
public static class RelationshipObject { | ||
|
||
/** | ||
* Could be a ResourceIdentifier (to-one) or a List of ResourceIdentifier (to-many) | ||
*/ | ||
private Object data; | ||
} | ||
|
||
/** | ||
* Defines a resource identifier object as per <a href="https://jsonapi.org/format/#document-resource-identifier-objects">...</a> | ||
*/ | ||
@Jacksonized | ||
@Builder | ||
@Getter | ||
public static class ResourceIdentifier { | ||
private String type; | ||
private UUID id; | ||
} | ||
} |