https://kotlinlang.org logo
Title
b

bjonnh

04/26/2019, 8:52 PM
This works:
@SolrDocument(solrCoreName ="indexedcitation")
class IndexedCitation {
    @Id
    @Indexed(name = "id", type = "string")
    private var id: String? = null

    @Indexed(name = "title", type = "string")
    private var title: String? = null


    fun getId(): String? {
        return id
    }

    fun setId(id: String?) {
        this.id = id
    }

    fun getTitle(): String? {
        return title
    }

    fun setTitle(title: String?) {
        this.title = title
    }
}
but not:
@SolrDocument(solrCoreName ="indexedcitation")
data class IndexedCitation(
    @Id
    @Indexed(name = "id", type = "string")
    private var id: String? = null,

    @Indexed(name = "title", type = "string")
    private var title: String? = null

)
p

Pavlo Liapota

04/26/2019, 9:00 PM
You can specify for which element annotation should be used: https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets
b

bjonnh

04/26/2019, 9:03 PM
so correct me if I'm wrong but in that case it would be @field:String ?
p

Pavlo Liapota

04/26/2019, 9:28 PM
@field:Id
I don’t know which target you need (field, set or get), you can try several.
b

bjonnh

04/26/2019, 9:52 PM
I can't set these on the @Indexed parameters
and trying all combinations on @Id do not change anything (the only one that work on @Indexed is field.
bytecode of the dataclass
bytecode of the public class
(no idea if it is useful or not)
ok it seems that the problem arises when I have a constructor
r

Robert Jaros

04/27/2019, 8:22 PM
Do you use allopen plugin? the classes are final in the bytecode you posted and spring doesn't like final classes - it can give weird errors.
b

bjonnh

04/27/2019, 8:35 PM
what is that plugin?
Is there any expected negative side effect of using that plugin?
r

Robert Jaros

04/27/2019, 9:00 PM
not really
👌 1
all your classes will be open by default just like in Java
there is also kotlin-spring plugin, which works the same way but only for classes annotated with Spring annotations
definitely worth applying before testing spring with kotlin
b

bjonnh

04/27/2019, 9:06 PM
first time I get stung by that but yep I'll clearly try that
But I cannot make data classes open
seems to work anyway. Thanks