简体   繁体   中英

Defining Implicit Writes

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM