Kevin Grant
Kevin Grant

Reputation: 591

SpringBoot MongoDB returns "Id must be assignable to Serializable! Object of class [null] must be an instance of interface java.io.Serializable"

I tried adding a new collection to my API/DB today, and when I try to POST or GET, I get this 500 error response:

{
  "cause": null,
  "message": "Id must be assignable to Serializable! Object of class [null] must be an instance of interface java.io.Serializable"
}

However the POST is actually successful, I can see the new data in the DB.

Model:

@Setter
@Getter
public class League {

    private String name;
    private String shortName;
    private List<Team> teams;
}

Repository:

@RepositoryRestResource(collectionResourceRel = "leagues", path = "leagues", excerptProjection = LeagueProjection.class)
public interface LeagueRepository extends MongoRepository<League, String> {

}

Projection:

@Projection(name="LeagueProjection", types={League.class})
public interface LeagueProjection {

    String getName();
    String getShortName();
}

I am not doing anything special. I have multiple other collections that work fine.

I am using spring-boot 1.5.1.

Thanks!

Upvotes: 2

Views: 2692

Answers (1)

Kevin Grant
Kevin Grant

Reputation: 591

Adding the field:

@Id private String id;

to my model seems to have resolved the issue.

Upvotes: 4

Related Questions