// NOTE: We take in a Resource instead of ResourceIdentifier here due to a deserialization // conflict public Relationship( @JsonProperty("links") Map<String, String> links, @JsonProperty("data") Data<Resource> data) { this.links = links; this.data = data; if (data != null) { if (data.isToOne()) { Resource resource = data.get().iterator().next(); this.idData = new Data<ResourceIdentifier>(resource != null ? resource.toResourceIdentifier() : null); } else { Collection<ResourceIdentifier> resourceIdentifiers = new ArrayList<ResourceIdentifier>(); for (Resource resource : data.get()) { resourceIdentifiers.add(resource.toResourceIdentifier()); } this.idData = new Data<ResourceIdentifier>(resourceIdentifiers); } } else { this.idData = null; } }