I am not a proffessional Spring Boot developer. I am writing a program with help from a tutorial and I am using Hateoas and Rest and when I am returning the response from a request I get a whitelabel error page.
The resourceobject itself looks to be correct when I try to write the values by using System.out.println().
This is the RestController-method.
@RequestMapping(method = RequestMethod.GET ,produces = {MediaType.APPLICATION_JSON_VALUE, "application/hal+json"})
Resources<SubjectResource> readSubject(@PathVariable String userId) {
this.validateUser(userId);
List<SubjectResource>subjectResource=subjectRepository.findByTeacherUsername(userId).stream().map(SubjectResource:: new).collect(Collectors.toList());
Resources <SubjectResource>r=new Resources<>(subjectResource);
return new Resources<>(subjectResource);
}
This is the imports I use in the RestController-class
import java.net.URI;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.hateoas.Link;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Resources;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
and this is the Resourcefile
import org.springframework.hateoas.Link;
import org.springframework.hateoas.ResourceSupport; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
class SubjectResource extends ResourceSupport {
private final Subject subject;
public SubjectResource(Subject subject) {
String username = subject.getTeacher().getUsername();
this.subject = subject;
this.add(new Link(subject.uri, "subject-uri"));
this.add(linkTo(SubjectRestController.class, username).withRel("subjects"));
this.add(linkTo(
methodOn(SubjectRestController.class, username).readSubject(username,
subject.getId())).withSelfRel());
}
public Subject getSubject() {
return subject;
}
}
and in my browser I typ
Do anyone know what I am doing wrong? Thanks /Micke