Spring Data Solr: map type field - spring-data-solr

is it possible to define in #SolrDocument a field with type Map<String, List<String>>?
I've tried using:
#Indexed(name = "words", type = "string")
var words: Map<String, List<String>>?
I'm setting that field as
val words = mapOf(Pair("1111", listOf("word1", "word2"))) but when saving to Solr this field isn't saved at all. And when this document is found by SolrRepository the value for field words is null.
What type in #Indexed annotation do I have to use to get Map type?

If you are still looking for an answer:
#Field("words_*")
#Dynamic
var words: Map<String, List<String>>?
should do the trick

Related

Jooq newRecord from map doesn't map camelCase to snake_case

I want to populate Record from Patch request that has stored values in map. However Jooq doesn't map camelCase keys in map to snake_case. Is there any possibility how to change that globally?
Data class example:
class PlantProtectionPatchRequest(val changes: Map<String, Any> = mapOf<String, Any>()) {
val decisionHolder: String? by changes
val isEko: Boolean? by changes
}
When i use dsl.newRecord(TABLE,plantProtection.changes) doesn't work, but dsl.newRecord(TABLE,plantProtection) would be mapped correctly. However i can't use the later, because it updates values that are not present in map to null.

No converter found capable of converting from type Map<String, Object> to org.neo4j.driver.Value

I'm trying to update properties in a Node by passing HashMap<String, Object> as node properties in custom query using #Query in spring-data-neo4j
query reference from neo4j documentation
#Query("MATCH (m:Person {nid: $from})\n" +
"SET m += $props" +
"RETURN m")
Person updateInfo(#Param("from") String id, #Param("props") Map<String, Object> properties);
where it throws error on type conversion as below:
No converter found capable of converting from type
[xxxxx.service.controllers.ProfileController$1] to type
[org.neo4j.driver.Value]
Is mutating specific properties like in raw query possible in spring-data-neo4j? Please suggest a way to use property map.

get declared fields in kotlin multiplatform

is there a way, to dynamically get reference to object field in kotlin multiplatform? I am trying to dynamically create instances of generic object from json input, in which I need to define exact field of a data object.
I have tried using reflections, but it is not available in multiplatform.
So I need something like
class User(
var lastName: String? = null,
var firstName: String? = null,
)
val jsonName="firstname"
val jsonModel="User::firstName"
val referenceJvm = User::class.declaredMembers // I cannot use this, only available for JVM
val referenceToField=User::firstName // I need to get this dynamically by using value in jsonModel property
StringField(
fieldName = jsonName,
model = referenceToField //this should be reference to firstName field in User class
)
Only solution I can think of is to have one huge dictionary/map where I would hardcode this. But application has hundreds possible models, so it is not really a solution I am looking for.

Returning projection with jsonb field

I'm using JPA as persistence API for a project. It contains an entity which has a Postgres jsonb column, such as below:
#Entity
#TypeDefs(value = [TypeDef(name = "jsonb", typeClass = JsonBinaryType::class)])
data class Post(
//... irrelevant columns
#Type("jsonb") #Column(columnDefinition = "jsonb") val postDefinitions: List<Map<String, Any>>
)
This works perfectly when fetching all data from this entity. But now I don't need to return all of it, but some fields, including the jsonb.
That's where things get ugly. I have this projection object and I'm using the following native query to retrieve the data, but somehow JPA can't map it.
interface PostProjection {
val id: UUID
val postDefinitions: List<Map<String, Any>>
}
#Query("SELECT CAST(id AS VARCHAR) AS id, jsonb_array_elements(post_definitions) AS postDefinitions " +
"FROM post WHERE id = :postId", nativeQuery = true)
fun getPostDefinitionsById(val id: UUID): List<PostProjection>
It already has the getters and setters. I have tried annotating the interface with #TypeDefs, the column with #Type and changing it from interface to data class.
No success. Couldn't find anything about this. I wouldn't like to retrieve a String and then map it to the corresponding data type.
Has someone went through it?

Getting annotation from constructor value parameter using kotlinpoet-metadata

I have data class like this
#Tagme("Response")
#TagResponse
data class Response(
val id: Int,
val title: String,
val label: String,
val images: List<String>,
#Input(Parameter::class)
val slug: Slug
)
Using annotation processor, I was able to get Response properties using this approach:
val parentMetadata = (element as TypeElement).toImmutableKmClass()
parentMetadata.constructors[0].valueParameters.map { prop ->
// this will loop through class properties and return ImmutableKmValueParameter
// eg: id, title, label, images, slug.
// then, I need to get the annotation that property has here.
// eg: #Input(Parameter::class) on slug property.
// if prop is slug, this will return true.
val isAnnotationAvailable = prop.hasAnnotations
// Here I need to get the annotated value
// val annotation = [..something..].getAnnotation(Input::class)
// How to get the annotation? So I can do this:
if ([prop annotation] has [#Input]) {
do the something.
}
}
Previously I tried to get the annotation like this:
val annotations = prop.type?.annotations
But, I got empty list even isAnnotationAvailable value is true
Thanks in advance!
Annotations are only stored in metadata if they have nowhere else they can be stored. For parameters, you must read them directly off of the Parameter (reflection) or VariableElement (elements API). This is why we have the ClassInspector API. You almost never want to try to read anything other than basic class data. Anything that's already contained in the bytecode or elements is basically never duplicated into metadata as well. Treat metadata as added signal, not a wholesale replacement.