java – Spring Hateoas,PathVariable和SaxSerialization

前端之家收集整理的这篇文章主要介绍了java – Spring Hateoas,PathVariable和SaxSerialization前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我实际上正在开发一个小应用程序来训练,我在使用 SpringHateoas使用PathVariable时遇到了问题.

事实上,当我使用类似的东西:

@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;
    }

我有一个像下面这样的错误

[com.sun.istack.internal.SAXException2]: unable to marshal type DirectoryDTO
to element because it’s missing an annotation

这是我的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 */
}

和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);
    }
}

我究竟做错了什么 ?

解决方法

您必须在DirectoryDTO中添加@XmlRootElement(name =“directoryEntity”)的注释.
原文链接:https://www.f2er.com/java/129170.html

猜你在找的Java相关文章