Java Interoperability
DSL Generation Note
Section titled “DSL Generation Note”The code generator (KSP) only processes Kotlin source files. For the best experience:
- Define your
@GraphViewclasses in Kotlin to get the generated type-safe DSL - Your
@NodeFragmentclasses can be in Java or Kotlin - At runtime, both Java and Kotlin classes work fully with the object manager
Recommended Pattern
Section titled “Recommended Pattern”Best Practice: Define @GraphView classes in Kotlin, everything else can be Java.
// Java fragments work great!@NodeFragment(labels = {"Person"})public class Person { @NodeId public UUID uuid; public String name; public String bio;}// Define GraphViews in Kotlin to get DSL generation@GraphViewdata class PersonContext( @Root val person: Person, // References Java class! @GraphRelationship(type = "WORKS_FOR") val worksFor: List<Organization>)// Use from Java with the fluent DSL APIList<PersonContext> results = JavaQueryBuilderKt .query(graphObjectManager, PersonContext.class) .filterWith(PersonContextQueryDsl.class) .where(dsl -> dsl.getPerson().getName().hasSubstring("Alice")) .loadAll();Summary
Section titled “Summary”| Feature | Java Support | Notes |
|---|---|---|
@NodeFragment |
✅ Full | Works identically in Java and Kotlin |
@RelationshipFragment |
✅ Full | Works identically in Java and Kotlin |
@GraphView runtime |
✅ Full | Loading, saving, polymorphism all work |
| Type-safe DSL | ✅ Full | Use filterWith() API from Java |
instanceOf() |
✅ Full | Filter by @NodeFragment subtype |
| DSL generation | ⚠️ Kotlin only | Define @GraphView in Kotlin |
| Generic collections | ✅ Full | Java reflection handles List<T>, Set<T> |
| Polymorphic types | ✅ Full | Works with sealed classes or @JsonSubTypes |

