1

I have a Java EE project that uses JOOQ to auto generate records using Kotin.

One such record is:

@Suppress("UNCHECKED_CAST")
open class EmailAddressRecord() : UpdatableRecordImpl<EmailAddressRecord>(EmailAddress.EMAIL_ADDRESS),
    Record5<Int?, Int?, String?, Boolean?, Boolean?> {

//...

  var isInList: Boolean?
    set(value) = set(3, value)
    get() = get(3) as Boolean?

When sent to the client via a GET method, the record is serialized into a json like { "isInList": true } as expected.

But if I send that back to a PUT method, I get an error about isInListnot being recognized. If instead I send a json with an inList property (without the is), the record is deserialized correctly on the server side.

There are several bits involved so I'm not even sure which is causing the issue:

  • Maybe it's because of how JOOQ generates the records with a var
  • Maybe it's Wildfly / RestEasy doing some funky stuff
  • Maybe it's Jackson not deserialising the record properly (I have tried to add the jackson kotlin module but it doesn't seem to make any difference)

Any pointers would be appreciated.

Versions: jackson 2.12.2, kotlin 1.4.10, widlfly 10, jooq 3.14.10

assylias
  • 321,522
  • 82
  • 660
  • 783
  • Reminds me of https://github.com/jOOQ/jOOQ/issues/11912. What happens if you annotate the property with `@set:JvmName("setIsInList")`? – Lukas Eder Jun 10 '21 at 12:19
  • Yup, solves the problem, nicely done! Even if not ideal since it will be removed at each codegen. I can see you used something like that to solve the issue. I may just need to bump JOOQ version up. – assylias Jun 10 '21 at 12:54
  • Ah, 14.12 not out on Central yet :-) – assylias Jun 10 '21 at 13:00
  • You could implement this as a regex-search-replace post processor after code generation. #11912 is not the same issue, but related. In kotlin, if a mutable property `x` exists, then there must not be another mutable property `isX`, or there will be a name clash in the generated setter. I think this `is` magic is quite the kotlin language design flaw, people keep running into this problem with or without jOOQ. Anyway, I wonder if we should just always generate that annotation on properties starting with `is`...? – Lukas Eder Jun 10 '21 at 13:01
  • @LukasEder Thanks for the regex tip. As for your last question, it would work fine in my case but I have no idea if it could break stuff for others... – assylias Jun 10 '21 at 13:03

1 Answers1

1

This is an extension of a fix that was implemented in jOOQ 3.15.0 and 3.14.12: https://github.com/jOOQ/jOOQ/issues/11912

The problem is that kotlin generates a setInList() setter for mutable properties named isInList, instead of setIsInList(). In the above issue, this can clash with an equally named setter for an inList property:

class X {
  var inList: Boolean?
  var isInList: Boolean?
}

I'm not convinced this is a useful optimisation in the jOOQ case. Instead of fixing #11912 only when there is such a name clash as above, we could just always generate the @set:JvmName("...") annotation on properties for columns starting with IS_:

class X {
  @set:JvmName("setIsInList")
  var isInList: Boolean?
}

And make this configurable, of course. These annotations can be turned of by specifying the following, starting from jOOQ 3.15.0:

<kotlinSetterJvmNameAnnotationsOnIsPrefix>false</kotlinSetterJvmNameAnnotationsOnIsPrefix>
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509