Skip to content

Java Interoperability

The code generator (KSP) only processes Kotlin source files. For the best experience:

  • Define your @GraphView classes in Kotlin to get the generated type-safe DSL
  • Your @NodeFragment classes can be in Java or Kotlin
  • At runtime, both Java and Kotlin classes work fully with the object manager

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
@GraphView
data class PersonContext(
@Root val person: Person, // References Java class!
@GraphRelationship(type = "WORKS_FOR")
val worksFor: List<Organization>
)
// Use from Java with the fluent DSL API
List<PersonContext> results = JavaQueryBuilderKt
.query(graphObjectManager, PersonContext.class)
.filterWith(PersonContextQueryDsl.class)
.where(dsl -> dsl.getPerson().getName().hasSubstring("Alice"))
.loadAll();
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