Skip to content

Commit

Permalink
Merge pull request #3555 from ebean-orm/feature/3503-kotlin-querybean…
Browse files Browse the repository at this point in the history
…-gen-DbMap

#3503 - Fix kotlin-querybean-generator for use of @DbMap
  • Loading branch information
rbygrave authored Feb 10, 2025
2 parents bb1b55e + 1ec26d1 commit 2dde23d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class SimpleQueryBeanWriter {
private static final Set<String> kotlinBlackListedImports = Collections.unmodifiableSet(
new HashSet<>(
Arrays.asList(
"?",
"extends",
"java.util.ArrayList",
"java.util.HashMap",
"java.util.HashSet",
Expand Down Expand Up @@ -213,18 +215,16 @@ private void writeConstructors() {
private void writeFields(boolean assocBeans) {
String padding = assocBeans ? " " : "";
for (PropertyMeta property : properties) {
String typeDefn = kotlinTypeDefn(property.getTypeDefn(shortName, assocBeans));
String typeDefn = toKotlinType(property.getTypeDefn(shortName, assocBeans));
writer.append("%s lateinit var %s: %s", padding, property.getName(), kotlinInnerType(typeDefn)).eol();
}
writer.eol();
}

private static String kotlinTypeDefn(String type) {
if (type.endsWith(",Integer>")) {
return type.replace(",Integer>", ",Int>");
} else {
return type;
}
private static String toKotlinType(String type) {
return type
.replace("? extends Object", "Any")
.replace(",Integer>", ",Int>");
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/test-kotlin/src/main/kotlin/org/example/Customer.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.order

import io.ebean.annotation.DbMap
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Version
Expand All @@ -15,4 +16,7 @@ class Customer(

@Version
var version: Long = 0

@DbMap(length = 800)
var params: Map<String, Any> = mapOf()
}

0 comments on commit 2dde23d

Please sign in to comment.