我今天尝试向我的 API/DB 添加一个新集合,当我尝试 POST 或 GET 时,我收到此 500 错误响应:
{
"cause": null,
"message": "Id must be assignable to Serializable! Object of class [null] must be an instance of interface java.io.Serializable"
}
但是 POST 实际上是成功的,我可以在数据库中看到新数据。
型号:
@Setter
@Getter
public class League {
private String name;
private String shortName;
private List<Team> teams;
}
存储库:
@RepositoryRestResource(collectionResourceRel = "leagues", path = "leagues", excerptProjection = LeagueProjection.class)
public interface LeagueRepository extends MongoRepository<League, String> {
}
投影:
@Projection(name="LeagueProjection", types={League.class})
public interface LeagueProjection {
String getName();
String getShortName();
}
我没有做任何特别的事情。我还有多个其他工作正常的集合。
我使用的是 spring-boot 1.5.1。
谢谢!
最佳答案
添加字段:
@Id private String id;
对于我的模型来说似乎已经解决了这个问题。
关于SpringBoot MongoDB 返回 "Id must be assignable to Serializable! Object of class [null] must be an instance of interface java.io.Serializable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42604007/