https://kotlinlang.org logo
#android
Title
# android
a

agrosner

10/22/2017, 12:45 PM
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

itsJoseph

10/22/2017, 12:53 PM
Yes, although I'm having this issue on parsing simplexml request value required and some sort
e

edwardwongtl

10/22/2017, 12:59 PM
Can you show your Java version and kotlin version?
k

kingsley

10/22/2017, 1:21 PM
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

itsJoseph

10/23/2017, 5:28 AM
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

kingsley

10/23/2017, 8:02 AM
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

itsJoseph

10/23/2017, 10:07 AM
it works! thanks a lot friend! 🙂
👍 1
10 Views