Skip to content

Commit 2960e5b

Browse files
aksOpsclaude
andcommitted
Fix Neo4j enum conversion: add NodeKind/EdgeKind converters for SDN
Spring Data Neo4j uses Enum.valueOf() by default, which expects uppercase constant names (METHOD, CLASS). But Neo4j stores lowercase values (method, class). Added @convertwith converters that map via fromValue()/getValue(). Fixes: IllegalArgumentException: No enum constant NodeKind.method Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 15e51df commit 2960e5b

4 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/main/java/io/github/randomcodespace/iq/model/CodeEdge.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class CodeEdge {
2323

2424
private String id;
2525

26+
@ConvertWith(converter = EdgeKindConverter.class)
2627
private EdgeKind kind;
2728

2829
private String sourceId;

src/main/java/io/github/randomcodespace/iq/model/CodeNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class CodeNode {
2323
@Id
2424
private String id;
2525

26+
@ConvertWith(converter = NodeKindConverter.class)
2627
private NodeKind kind;
2728

2829
private String label;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.github.randomcodespace.iq.model;
2+
3+
import org.neo4j.driver.Value;
4+
import org.springframework.data.neo4j.core.convert.Neo4jPersistentPropertyConverter;
5+
6+
/**
7+
* Converts between EdgeKind enum and its lowercase string value for Neo4j storage.
8+
* Neo4j stores "depends_on", "calls", etc. — not "DEPENDS_ON", "CALLS".
9+
*/
10+
public class EdgeKindConverter implements Neo4jPersistentPropertyConverter<EdgeKind> {
11+
12+
@Override
13+
public Value write(EdgeKind kind) {
14+
return org.neo4j.driver.Values.value(kind != null ? kind.getValue() : null);
15+
}
16+
17+
@Override
18+
public EdgeKind read(Value source) {
19+
if (source == null || source.isNull()) return null;
20+
return EdgeKind.fromValue(source.asString());
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.github.randomcodespace.iq.model;
2+
3+
import org.neo4j.driver.Value;
4+
import org.springframework.data.neo4j.core.convert.Neo4jPersistentPropertyConverter;
5+
6+
/**
7+
* Converts between NodeKind enum and its lowercase string value for Neo4j storage.
8+
* Neo4j stores "method", "class", etc. — not "METHOD", "CLASS".
9+
*/
10+
public class NodeKindConverter implements Neo4jPersistentPropertyConverter<NodeKind> {
11+
12+
@Override
13+
public Value write(NodeKind kind) {
14+
return org.neo4j.driver.Values.value(kind != null ? kind.getValue() : null);
15+
}
16+
17+
@Override
18+
public NodeKind read(Value source) {
19+
if (source == null || source.isNull()) return null;
20+
return NodeKind.fromValue(source.asString());
21+
}
22+
}

0 commit comments

Comments
 (0)