spring-projects / spring-projects/spring-data-rest
Getting error "Id must be assignable to Serializable" with simple Neo4j repository [DATAREST-928]
@mp911de is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Florian opened DATAREST-928 and commented
I'am building a simple Spring Boot app with Spring Data Rest and Neo4j.
I followed the instruction guide here: https://spring.io/guides/gs/accessing-neo4j-data-rest/
Here is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>my-service</artifactId>
<packaging>jar</packaging>
<name>my-service</name>
<description>my-service</description>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version>
<jackson.version>2.7.0</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here is my entity TreeComponent:
package myservice.entities;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import org.neo4j.ogm.annotation.typeconversion.Convert;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@NodeEntity
@JsonIgnoreProperties(ignoreUnknown = true)
public class TreeComponent implements Serializable {
@GraphId
private Long id;
@NotNull
private String source;
private String name;
@Convert(DataConverter.class)
private JsonNode data = JsonNodeFactory.instance.objectNode();
private String urlPart;
private String content;
@Relationship
public Set<TreeComponent> children = new HashSet<>();
public TreeComponent() {
}
public Set<TreeComponent> getChildren() {
return children;
}
public void setChildren(Set<TreeComponent> children) {
this.children = children;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public JsonNode getData() {
return this.data;
}
public void setData(JsonNode data) {
this.data = data;
}
public String getUrlPart() {
return urlPart;
}
public void setUrlPart(String urlPart) {
this.urlPart = urlPart;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The repository class TreeComponentRepository:
package myservice.rest.repositories;
import myservice.entities.TreeComponent;
import org.springframework.data.neo4j.repository.GraphRepository;
public interface TreeComponentRepository extends GraphRepository<TreeComponent> {
}
Finally, the annotations used on the Spring boot app class:
@SpringBootApplication
@EnableDiscoveryClient
@EnableNeo4jRepositories
Everything works fine, I even got my data in the Neo4j database (+with IDs+). Unfortunately, I've got the following error when accessing my data through the rest API (http://localhost:8861/api/treeComponents):
cause: null,
message: "Id must be assignable to Serializable! Object of class [null] must be an instance of interface java.io.Serializable"
Is it a bug or am i missing something ?
Thanks for the help.
Affects: 2.5.4 (Hopper SR4)
Issue Links:
- DATAGRAPH-918 Neo4jPersistentProperty does not resolve Id property
("depends on")
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.