#787 - Return all Link attributes on discovery.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.hateoas.hal;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.core.JsonPathLinkDiscoverer;
|
||||
@@ -23,10 +26,35 @@ import org.springframework.hateoas.core.JsonPathLinkDiscoverer;
|
||||
* {@link LinkDiscoverer} implementation based on HAL link structure.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class HalLinkDiscoverer extends JsonPathLinkDiscoverer {
|
||||
|
||||
/**
|
||||
* Constructor for {@link MediaTypes#HAL_JSON}.
|
||||
*/
|
||||
public HalLinkDiscoverer() {
|
||||
super("$._links..['%s']..href", MediaTypes.HAL_JSON);
|
||||
super("$._links..['%s']", MediaTypes.HAL_JSON, MediaTypes.HAL_JSON_UTF8);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Link extractLink(Object element, String rel) {
|
||||
|
||||
if (element instanceof Map) {
|
||||
|
||||
Map<String, String> json = (Map<String, String>) element;
|
||||
|
||||
return new Link(json.get("href"), rel)
|
||||
.withHreflang(json.get("hreflang"))
|
||||
.withMedia(json.get("media"))
|
||||
.withTitle(json.get("title"))
|
||||
.withType(json.get("type"))
|
||||
.withDeprecation(json.get("deprecation"))
|
||||
.withProfile(json.get("profile"))
|
||||
.withName(json.get("name"));
|
||||
}
|
||||
|
||||
return super.extractLink(element, rel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.hateoas.hal.forms;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.core.JsonPathLinkDiscoverer;
|
||||
|
||||
@@ -26,6 +29,27 @@ import org.springframework.hateoas.core.JsonPathLinkDiscoverer;
|
||||
public class HalFormsLinkDiscoverer extends JsonPathLinkDiscoverer {
|
||||
|
||||
public HalFormsLinkDiscoverer() {
|
||||
super("$._links..['%s']..href", MediaTypes.HAL_FORMS_JSON);
|
||||
super("$._links..['%s']", MediaTypes.HAL_FORMS_JSON);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Link extractLink(Object element, String rel) {
|
||||
|
||||
if (element instanceof Map) {
|
||||
|
||||
Map<String, String> json = (Map<String, String>) element;
|
||||
|
||||
return new Link(json.get("href"), rel)
|
||||
.withHreflang(json.get("hreflang"))
|
||||
.withMedia(json.get("media"))
|
||||
.withTitle(json.get("title"))
|
||||
.withType(json.get("type"))
|
||||
.withDeprecation(json.get("deprecation"))
|
||||
.withProfile(json.get("profile"))
|
||||
.withName(json.get("name"));
|
||||
}
|
||||
|
||||
return super.extractLink(element, rel);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user