Thanks for the quick response. I tried changing @AllArgsConstructor
to just @Setter
which didn't throw any error, but it also does not work anymore. The result I get in JSON was either "id": 0 or nothing at all.
Here is my code:
// @Getter
@Setter
// @AllArgsConstructor
// @Data
@Node
public class Person {
@Id @GeneratedValue @Setter(AccessLevel.PRIVATE) @Getter(AccessLevel.PUBLIC)
private Long id;
private String firstName;
private String lastName;
// HAVING BOTH OF THESE RELATIONSHIPS CAUSES CYLCES IN THE GRAPH
@Relationship(type = "HAS_CHILD", direction = Direction.OUTGOING)
private List<Person> children; //using set bc its unordered and has no duplicates.
@Relationship(type = "HAS_CHILD", direction = Direction.INCOMING)
private List<Person> parents; //using set bc its unordered and has no duplicates.
}
My expected results are supposed to match the neo4j model in nested JSON. But, I get "id":0
for 0, and [ ]
for any other id provided:
Here is my Person repo again:
@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends Neo4jRepository<Person, Long> {
List<Person> findByFirstNameStartsWithIgnoreCaseAndLastNameStartsWithIgnoreCase(String firstName, String lastName);
@Query(
"MATCH (refNode:Person WHERE ID(refNode) = $id) -[r_parent:HAS_CHILD*]-> (child:Person)" +
"MATCH (refNode) <-[r_child:HAS_CHILD*]- (parent)" +
"RETURN refNode, collect(r_parent), collect(child), collect(parent)"
)
List<Person> findChildrenAndParents(@Param("id") Long id);
If I use @Data
instead (chose this bc it doesn't have an @AllArgsConstructor to it), I get an infinite loop error in my terminal. However, SwaggerUI doesn't know how to respond and returns Error: response status is 200
.
// @Getter
// @Setter
// @AllArgsConstructor
@Data
@Node
public class Person {
@Id @GeneratedValue @Setter(AccessLevel.PRIVATE) @Getter(AccessLevel.PUBLIC)
private Long id;
private String firstName;
private String lastName;
// HAVING BOTH OF THESE RELATIONSHIPS CAUSES CYLCES IN THE GRAPH
@Relationship(type = "HAS_CHILD", direction = Direction.OUTGOING)
private List<Person> children; //using set bc its unordered and has no duplicates.
@Relationship(type = "HAS_CHILD", direction = Direction.INCOMING)
private List<Person> parents; //using set bc its unordered and has no duplicates.
}
Here is the looping error:
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:119) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:772) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:119) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:772) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:119) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18) ~[jackson-databind-2.15.3.jar:2.15.3]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.15.3.jar:2.15.3]
and it keeps doing that for all of my functions.
Thank you again for the help, please let me know what could be the issue.