0
votes

I am writing implicit writes for a few Java DO Classes so I can use Json.toJson() to return the data as a JSON String.

I created an object ImplicitsWrites where I have them and imported it into my controller class.

However, during complilation I get: value getUserId is not a member of com.domain.UserDO Note: implicit value <myDOClass> is not applicable here because it comes after the application point and it lacks an explicit result type

Just a note, getUserId() is valid method in the DO.

An example write is this:

implicit val userDOWrite = new Writes[UserDO] {
    def writes(userDO: UserDO) = Json.obj(
      "userId" -> userDO.getUserId(),
      "rowType" -> userDO.getName()
    )
  }

Just a note. Maybe this will help identify the problem. The DO has @Data annotation (lombok) so the get/set methods are generated.

Am I defining the implicit wrong? If so, what is the proper way of doing it?

1
extends AnyRef has nothing to do there. The main issue is value getUserId is not a member of com.domain.UserDO. Check in the scala console import com.domain.UserDO; new UserDO(..).getUserId - cchantep
Just a note. Maybe this will help identify the problem. The DO has @Data annotation (lombok) so the get/set methods are generated. - Petre Popescu
You can check it in the Scala console (e.g. console from SBT) - cchantep
Is the JAR/package containing your Java DO POJO's already built? Lombok uses macros at compile time so as far as the Scala compiler is concerned those getters don't exist unless you're referencing code that is already compiled. If you're doing Java/Scala in the same project I'd reason that it is incompatible in this case. - Tyler James Harden
Yes. i am doing Java and Scala in the same project. Already made a test and saw that if I manually create the getter() it works. - Petre Popescu

1 Answers

0
votes

Scala does not recognize lombok getter/setters unless the file is already compiled. For projects that are a mix of both java and Scala, lombok is not currently properly supported.