Title
i

ikozlowski

06/27/2017, 2:33 PM
hi, anyone here tried to use kotlin with hibernate and jackson? (also spring, but i dont think this is important here) after adding kotlin-noarg and kotlin-jpa to my project I got
com.fasterxml.jackson.databind.JsonMappingException: Could not find creator property with name zxc
errors for entities that works without this plugin
stdlib-jre8, kotlin-reflect, 1.1.2-5
jackson-core, jackson-datatype-jsr310, jackson-module-kotlin 2.8.9
hibernate-java8 5.2.10.Final
a

agomez

06/27/2017, 2:35 PM
ikozlowski: try adding this dependency
com.fasterxml.jackson.module:jackson-module-kotlin
i

ikozlowski

06/27/2017, 2:36 PM
also have it
f

fred.deschenes

06/27/2017, 2:42 PM
have you registered the kotlin module on your ObjectMapper?
i

ikozlowski

06/27/2017, 2:43 PM
there is no need afaik in spring-web-4.3.7.RELEASE-sources.jar!\converter\json\Jackson2ObjectMapperBuilder.java:772 module is registered by spring, and i can see it in integration test
f

fred.deschenes

06/27/2017, 2:45 PM
I didn't know Spring registered the module automatically
can you post the class you're trying to deserialize?
i

ikozlowski

06/27/2017, 2:46 PM
@Entity
@Table(uniqueConstraints = arrayOf(UniqueConstraint(columnNames = arrayOf("form_id", "ref"))))
@JsonInclude(JsonInclude.Include.NON_EMPTY)
class FormNode (
        var ref: String = UUID.randomUUID().toString(),
        val name: String = "",
        var type: FormNodeType,
        var position: Int = 0,

        @ElementCollection
        val binding: Map<FormBinding, String> = emptyMap(),

        @OneToMany(cascade = arrayOf(CascadeType.ALL), orphanRemoval = true)
        val children: List<FormNode> = emptyList(),

        @JsonIgnore
        @ManyToOne(fetch = FetchType.LAZY)
        var form: Form? = null) : BaseEntity() {

    enum class FormNodeType {
        GROUP,
        TEXT,
        INT,
        SLIDER,
        RADIO,
        MULTISELECT,
        SELECTABLE
    }

    enum class FormBinding {
        SHOW_WHEN_SELECTED,
        HIDE_WHEN_SELECTED
    }
when I don't add kotlin-jpa, I recieve expected error form hibernate that there is no default constructor but jackson serialization works correctly
s

sdeleuze

06/27/2017, 3:32 PM
Try https://github.com/sdeleuze/spring-boot-kotlin-demo it seems to work correctly
👍 1
i

ikozlowski

06/27/2017, 5:23 PM
thanks for suggestion, I forked and added my data, but have problem with settting up integration test, I get 404 when I would expect to get entity link to my fork: https://github.com/Kinmarui/spring-boot-kotlin-demo