-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate document source #45
Comments
Possibly it is worth to generate data class for a document source. Generated code could look like: data class GroupDocSource(
val id: Int,
val name: String,
) {
constructor(src: Deserializer.ObjectCtx) :
this(
// TODO: What if there are multiple GroupDoc fields in a parent document?
id = UserDoc.group.id.getFieldType().deserialize(src.any("id")),
name = UserDoc.group.name.getFieldType().deserialize(src.any("name")),
)
override fun toSource(ctx: Serializer.ObjectCtx) {
ctx.field("id", id)
ctx.field("name", name)
}
}
data class UserDocSource(
val id: Int,
val groups: List<GroupDocSource>,
val login: String,
val about: String?,
) : ToSource {
companion object {
private val groupsFieldType = RequiredListType(UserDoc.groups.getFieldType())
}
constructor(src: Deserializer.ObjectCtx) :
this(
id = UserDoc.id.getFieldType().deserialize(src.any("id")),
groups = groupsFieldType.deserialize(src.any("groups")),
login = UserDoc.login.getFieldType().deserialize(src.any("login")),
about = src.anyOrNull("about")?.let(UserDoc.about.getFieldType()::deserialize),
)
override fun toSource(ctx: Serializer.ObjectCtx) {
ctx.field("id", id)
ctx.array("groups") {
for (groupsItem in groups) {
obj {
groupsItem.toSource(this)
}
}
}
ctx.field("login", login)
ctx.field("about", about)
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Research a way how we could generate a document source from a document.
An example how it may look like:
Should generate document source that matches:
Also we could generate more effective fersion. See an example:
elasticmagic-kt/src/commonTest/kotlin/dev/evo/elasticmagic/doc/DocSourceTests.kt
Line 209 in 7e53497
Links:
The text was updated successfully, but these errors were encountered: