Android studio -> convert to kotlin. retrofit i...
# android
a
Android studio -> convert to kotlin. retrofit is just an interface. You don't need a kotlin example. It's the same just with kotlin syntax
i
Yes, although I'm having this issue on parsing simplexml request value required and some sort
e
Can you show your Java version and kotlin version?
k
As explained already. There’s nothing conceptually different. Just slight syntactical differences as expected for a different language.
Copy code
// Java
public interface SomeService {

  @GET(...)
  Call<Foo> fetchFoo(@Query(...) String someParam);
}

//Kotlin
interface SomeService {
  @GET(...)
  fun fetchFoo(@Query(...) someParam: String): Call<Foo>
}
Feel free to look up Kotlin’s online reference: https://kotlinlang.org/docs/reference/basic-syntax.html
i
i get this error " org.simpleframework.xml.core.MethodException: Annotation @org.simpleframework.xml.Element(data=false, name=svc:ActivateApp, required=false, type=void) must mark a set or get method "
as my request looks like this.. @Root(name = "soapenv:Envelope") @NamespaceList(Namespace(prefix = "soapenv", reference = "http://schemas.xmlsoap.org/soap/envelope/"), Namespace(prefix = "svc", reference = "http://svc.sdgroup.com"), Namespace(prefix = "sdg", reference = "http://schemas.datacontract.org/2004/07/SDGWebService.Classes")) class ActivationWSReq { @Element(name = "soapenv:Header", required = false) private var activationHeader: ActivationHeader? = null @Element(name = "soapenv:Body", required = false) private var activationRequest: ActivationRequest? = null fun getActivationHeader(): ActivationHeader? { return activationHeader } fun setActivationHeader(activationHeader: ActivationHeader) { this.activationHeader = activationHeader } fun getActivationRequest(): ActivationRequest? { return activationRequest } fun setActivationRequest(activationRequest: ActivationRequest) { this.activationRequest = activationRequest } @Root(name = "soapenv:Header", strict = false) class ActivationHeader @Root(name = "soapenv:Body", strict = false) class ActivationRequest { @Element(name = "svc:ActivateApp", required = false) var activationMethod: ActivationMethod? = null }
this structure worked on my Java project but when I convert this to Kotlin, such error came out
k
I see. You’ll need to change the
@Element
into something like
@get:Element
or
@set:Element
depending on whether it should be on the getter/setter accordingly. In fact. Looking at your code again. You could reduce it to something like this:
Copy code
@(...)
class ActivationWSReq(
  @(...) var activationHeader: ActivationHeader? = null, //Perhaps change @Element here to @get:Element
  @(...) var activationRequest: ActivationRequest? = null
)

@(...)
class ActivationHeader

@(...)
class ActivationRequest(
  @(...) var activationMethod: ActivationMethod? = null
)
i
it works! thanks a lot friend! 🙂
👍 1