Skip to content

Commit

Permalink
improve JsonDsl API
Browse files Browse the repository at this point in the history
  • Loading branch information
jillesvangurp committed Dec 25, 2022
1 parent 9c82a0c commit 754eb68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ interface IJsonDsl : MutableMap<String, Any> {
namingConvention: PropertyNamingConvention = PropertyNamingConvention.ConvertToSnakeCase
)

operator fun <T> get(key: String,namingConvention: PropertyNamingConvention=defaultNamingConvention): T?
fun <T> get(key: KProperty<*>, namingConvention: PropertyNamingConvention=defaultNamingConvention): T?

/**
* Property delegate that stores the value in the MapBackedProperties. Use this to create type safe
* properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ open class JsonDsl(
) : MutableMap<String, Any> by _properties, IJsonDsl {
override val defaultNamingConvention: PropertyNamingConvention = namingConvention

override fun get(key: String) = _properties[key.convertPropertyName(namingConvention)]
override fun <T> get(key: String,namingConvention: PropertyNamingConvention) = _properties[key.convertPropertyName(namingConvention)] as T
override fun <T> get(key: KProperty<*>,namingConvention: PropertyNamingConvention) = get(key.name,namingConvention) as T

override fun put(key: KProperty<*>, value: Any, namingConvention: PropertyNamingConvention) {
_properties[key.name.convertPropertyName(namingConvention)] = value
}
override fun put(key: String, value: Any, namingConvention: PropertyNamingConvention) {
_properties[key.convertPropertyName(namingConvention)] = value
}

override fun put(key: String, value: Any) {
_properties[key.convertPropertyName(namingConvention)] = value
override fun put(key: KProperty<*>, value: Any, namingConvention: PropertyNamingConvention) {
_properties[key.name.convertPropertyName(namingConvention)] = value
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class SearchDSL : JsonDsl() {

var aggs: JsonDsl
get() = this["aggs"] as JsonDsl
set(value) = this.put("aggs", value)
set(value) {
this["aggs"] = value
}
}

enum class SortOrder { ASC, DESC }
Expand Down

0 comments on commit 754eb68

Please sign in to comment.