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
"data" : { | |
"full-name": "M. Smith", | |
"email" : "[email protected]" | |
} |
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
"data" : [ | |
{"name" : "full-name", "value" : "M. Smith", "prompt" : "Full Name"}, | |
{"name" : "email", "value" : "[email protected]", "prompt" : "Email"} | |
] |
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
@Data | |
@Value | |
@Builder(builderMethodName = "collectionJson") | |
public class CollectionJson<T> { | |
private String version; | |
private String href; | |
private List<Link> links; | |
@Singular private List<Item<T>> items; |
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
CollectionJson collectionJson = collectionJson() | |
.version("1.0") | |
.href(resource.getId().expand().getHref()) | |
.links(value) | |
.items(Collections.EMPTY_LIST) | |
.build(); |
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
public abstract class AffordanceModelFactory implements Plugin<MediaType> { | |
abstract public MediaType getMediaType(); | |
abstract public List<AffordanceModel> findAffordanceModels(Affordance affordance, Object invocationValue); | |
@Override | |
public boolean supports(MediaType delimiter) { | |
return delimiter != null && delimiter.equals(this.getMediaType()); | |
} |
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
public interface Affordance { | |
/** | |
* HTTP method this affordance covers. For multiple methods, add multiple {@link Affordance}s. | |
* | |
* @return | |
*/ | |
String getHttpMethod(); | |
/** |
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
@GetMapping("/employees/{id}") | |
public Resource<Employee> findOne(@PathVariable String id) { | |
// Start the affordance with the "self" link, i.e. this method. | |
Link findOneLink = | |
linkTo(methodOn(EmployeeController.class).findOne(id)).withSelfRel(); | |
// Define final link as means to find entire collection. | |
Link employeesLink = linkTo(methodOn(EmployeeController.class).all()).withRel("employees"); |
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
@Value | |
@JsonPropertyOrder({"id", "name", "employees"}) | |
class Supervisor { | |
@JsonIgnore | |
private final Manager manager; | |
public Long getId() { | |
return this.manager.getId(); | |
} |
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
@GetMapping(value = "/supervisors/{id}", produces = MediaTypes.HAL_JSON_VALUE) | |
public ResponseEntity<Resource<Supervisor>> findOne(@PathVariable Long id) { | |
Resource<Manager> managerResource = controller.findOne(id).getBody(); | |
Resource<Supervisor> supervisorResource = new Resource<>( | |
new Supervisor(managerResource.getContent()), | |
managerResource.getLinks()); | |
return ResponseEntity.ok(supervisorResource); | |
} |
NewerOlder