reified mapAsObject

This commit is contained in:
DBotThePony 2023-01-22 19:10:20 +07:00
parent 6f8de045e1
commit 580cfd53da
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 12 additions and 3 deletions

View File

@ -263,10 +263,10 @@ data class RenderTemplate(
companion object { companion object {
val ADAPTER = FactoryAdapter.Builder(RenderTemplate::class) val ADAPTER = FactoryAdapter.Builder(RenderTemplate::class)
.mapAsObject(RenderTemplate::pieces, RenderPiece::class.java) .mapAsObject(RenderTemplate::pieces)
.auto(RenderTemplate::representativePiece) .auto(RenderTemplate::representativePiece)
.list(RenderTemplate::matches, RenderMatchList::class.java) .autoList(RenderTemplate::matches)
.mapAsObject(RenderTemplate::rules, RenderRuleList::class.java) .mapAsObject(RenderTemplate::rules)
.build() .build()
val CACHE = ADAPTER.asReference() val CACHE = ADAPTER.asReference()

View File

@ -560,6 +560,15 @@ class FactoryAdapter<T : Any> private constructor(
return this return this
} }
/**
* Добавляет поле-таблицу, которое кодируется как {"a": value, "b": value, ...}
*
* Таблица неизменяема (создаётся объект [ImmutableMap])
*/
inline fun <reified V> mapAsObject(field: KProperty1<T, Map<String, V>?>): Builder<T> {
return mapAsObject(field, V::class.java)
}
/** /**
* Добавляет поле-таблицу, которое кодируется как {"a": value, "b": value, ...} * Добавляет поле-таблицу, которое кодируется как {"a": value, "b": value, ...}
* *