logMisses флаги и ещё парочка штук
This commit is contained in:
parent
b077b22180
commit
c42cde3372
@ -52,6 +52,7 @@ data class ThingDescription(
|
|||||||
val ADAPTER = FactoryAdapter.Builder(ThingDescription::class,
|
val ADAPTER = FactoryAdapter.Builder(ThingDescription::class,
|
||||||
ThingDescription::shortdescription,
|
ThingDescription::shortdescription,
|
||||||
ThingDescription::description)
|
ThingDescription::description)
|
||||||
|
.logMisses(false)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,9 +154,8 @@ class BuilderAdapter<T : Any> private constructor(
|
|||||||
throw JsonSyntaxException("$name is not a valid property of ${instance::class.qualifiedName}")
|
throw JsonSyntaxException("$name is not a valid property of ${instance::class.qualifiedName}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logMisses && !loggedMisses.contains(name)) {
|
if (logMisses && loggedMisses.add(name)) {
|
||||||
LOGGER.warn("${instance::class.qualifiedName} has no property for storing $name")
|
LOGGER.warn("${instance::class.qualifiedName} has no property for storing $name")
|
||||||
loggedMisses.add(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.skipValue()
|
reader.skipValue()
|
||||||
@ -245,7 +244,7 @@ class BuilderAdapter<T : Any> private constructor(
|
|||||||
private val flatProperties = ArrayList<WrappedProperty<T, *>>()
|
private val flatProperties = ArrayList<WrappedProperty<T, *>>()
|
||||||
private val ignoreKeys = ObjectArraySet<String>()
|
private val ignoreKeys = ObjectArraySet<String>()
|
||||||
var extraPropertiesAreFatal = false
|
var extraPropertiesAreFatal = false
|
||||||
var logMisses = true
|
var logMisses: Boolean? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Являются ли "лишние" ключи в JSON структуре ошибкой.
|
* Являются ли "лишние" ключи в JSON структуре ошибкой.
|
||||||
@ -320,6 +319,8 @@ class BuilderAdapter<T : Any> private constructor(
|
|||||||
* Данный подход позволяет избавиться от постоянного наследования и реализации одного и того же интерфейса во множестве других классов.
|
* Данный подход позволяет избавиться от постоянного наследования и реализации одного и того же интерфейса во множестве других классов.
|
||||||
*
|
*
|
||||||
* Флаг [extraPropertiesAreFatal] не поддерживается с данными свойствами
|
* Флаг [extraPropertiesAreFatal] не поддерживается с данными свойствами
|
||||||
|
*
|
||||||
|
* Если [logMisses] не указан явно, то он будет выставлен на false
|
||||||
*/
|
*/
|
||||||
fun <V> flat(property: KMutableProperty1<T, V>, adapter: TypeAdapter<V>, configurator: PropertyConfigurator<T, V>.() -> Unit = {}): Builder<T> {
|
fun <V> flat(property: KMutableProperty1<T, V>, adapter: TypeAdapter<V>, configurator: PropertyConfigurator<T, V>.() -> Unit = {}): Builder<T> {
|
||||||
val config = _add(property, adapter, configurator)
|
val config = _add(property, adapter, configurator)
|
||||||
@ -413,7 +414,7 @@ class BuilderAdapter<T : Any> private constructor(
|
|||||||
flatProperties = map2.build(),
|
flatProperties = map2.build(),
|
||||||
ignoreKeys = ImmutableSet.copyOf(ignoreKeys),
|
ignoreKeys = ImmutableSet.copyOf(ignoreKeys),
|
||||||
extraPropertiesAreFatal = extraPropertiesAreFatal,
|
extraPropertiesAreFatal = extraPropertiesAreFatal,
|
||||||
logMisses = logMisses,
|
logMisses = logMisses ?: flatProperties.isEmpty(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ class FactoryAdapter<T : Any> private constructor(
|
|||||||
val bound: KClass<T>,
|
val bound: KClass<T>,
|
||||||
private val types: ImmutableList<PackedProperty<T, *>>,
|
private val types: ImmutableList<PackedProperty<T, *>>,
|
||||||
val asJsonArray: Boolean,
|
val asJsonArray: Boolean,
|
||||||
val storesJson: Boolean
|
val storesJson: Boolean,
|
||||||
|
val logMisses: Boolean,
|
||||||
) : TypeAdapter<T>() {
|
) : TypeAdapter<T>() {
|
||||||
private data class PackedProperty<Clazz : Any, T>(
|
private data class PackedProperty<Clazz : Any, T>(
|
||||||
val property: KProperty1<Clazz, T>,
|
val property: KProperty1<Clazz, T>,
|
||||||
@ -247,7 +248,7 @@ class FactoryAdapter<T : Any> private constructor(
|
|||||||
val fieldId = name2index.getInt(name)
|
val fieldId = name2index.getInt(name)
|
||||||
|
|
||||||
if (fieldId == -1) {
|
if (fieldId == -1) {
|
||||||
if (!storesJson && !hasFlatValues && loggedMisses.add(name)) {
|
if (!storesJson && !hasFlatValues && logMisses && loggedMisses.add(name)) {
|
||||||
if (currentSymbolicName == null) {
|
if (currentSymbolicName == null) {
|
||||||
LOGGER.warn("${bound.qualifiedName} has no property for storing $name ")
|
LOGGER.warn("${bound.qualifiedName} has no property for storing $name ")
|
||||||
} else {
|
} else {
|
||||||
@ -396,8 +397,21 @@ class FactoryAdapter<T : Any> private constructor(
|
|||||||
*/
|
*/
|
||||||
var storesJson = false
|
var storesJson = false
|
||||||
|
|
||||||
fun storesJson(): Builder<T> {
|
/**
|
||||||
storesJson = true
|
* Логировать ли несуществующие свойства у класса когда они попадаются в исходной JSON структуре
|
||||||
|
*/
|
||||||
|
var logMisses = true
|
||||||
|
|
||||||
|
fun storesJson(flag: Boolean = true): Builder<T> {
|
||||||
|
storesJson = flag
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Логировать ли json значения которые нет в списке свойств
|
||||||
|
*/
|
||||||
|
fun logMisses(flag: Boolean = true): Builder<T> {
|
||||||
|
logMisses = flag
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,6 +586,7 @@ class FactoryAdapter<T : Any> private constructor(
|
|||||||
types = ImmutableList.copyOf(types),
|
types = ImmutableList.copyOf(types),
|
||||||
asJsonArray = asList,
|
asJsonArray = asList,
|
||||||
storesJson = storesJson,
|
storesJson = storesJson,
|
||||||
|
logMisses = logMisses,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user