All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.katharsis.resource.Resource Maven / Gradle / Ivy

The newest version!
package io.katharsis.resource;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
 * “Resource objects” appear in a JSON API document to represent resources.
 * 

* http://jsonapi.org/format/#document-resource-objects */ public class Resource extends ResourceIdentifier implements MetaContainer, LinksContainer { @JsonInclude(Include.NON_EMPTY) private Map attributes = new HashMap<>(); @JsonInclude(Include.NON_EMPTY) private Map relationships = new HashMap<>(); @JsonInclude(Include.NON_EMPTY) private ObjectNode links; @JsonInclude(Include.NON_EMPTY) private ObjectNode meta; @Override public ObjectNode getLinks() { return links; } @Override public void setLinks(ObjectNode links) { this.links = links; } @Override public ObjectNode getMeta() { return meta; } @Override public void setMeta(ObjectNode meta) { this.meta = meta; } public Map getAttributes() { return attributes; } public void setAttributes(Map attributes) { this.attributes = attributes; } public Map getRelationships() { return relationships; } public void setRelationships(Map relationships) { this.relationships = relationships; } public void setAttribute(String name, JsonNode value) { attributes.put(name, value); } @Override public int hashCode() { return Objects.hash(attributes, relationships, links, meta); } @Override public boolean equals(Object obj) { if (!(obj instanceof Resource)) return false; Resource other = (Resource) obj; return Objects.equals(attributes, other.attributes) && Objects.equals(relationships, other.relationships) && Objects.equals(meta, other.meta) && Objects.equals(links, other.links); } public ResourceIdentifier toIdentifier() { return new ResourceIdentifier(getId(), getType()); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy