Java – spring HATEOAS, pathvariable and saxserialization
•
Java
I'm actually developing a small application to train, and I have a problem using spring HATEOAS and pathvariable
In fact, when I use something similar:
@RequestMapping(value = "/directories/{idDirectory}",method = RequestMethod.GET)
public DirectoryDTO findById(@PathVariable String idDirectory) {
DirectoryEntity directoryEntity = directoryService.findById(idDirectory);
DirectoryDTO directoryDto = new DirectoryDTO(directoryEntity);
directoryDto.add(linkTo(methodOn(DirectoryController.class).findById(idDirectory)).withSelfRel());
return directoryDto;
}
I have a mistake like this:
This is my directoryentity:
@Document(collection = "directory")
public class DirectoryEntity {
@Id
private String id;
private String name;
private String path;
private List<DirectoryEntity> childrenDirectories;
private DirectoryEntity parentDirectory;
private List<FileEntity> fileEntities;
/* Get/set omitted */
}
And dto:
public class DirectoryDTO extends Resource<DirectoryEntity> {
public DirectoryDTO(DirectoryEntity content,Link... links) {
super(content,links);
}
public DirectoryDTO(DirectoryEntity content,Iterable<Link> links) {
super(content,links);
}
}
What on earth did I do wrong?
Solution
You must add a comment for @ xmlrootelement (name = "directoryentity") in directorydto
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
