Error using @POST with @Body in interface Retrofit on Android

0

I have a problem using Retrofit in a project that manages Java and Kotlin at the same time and I can not find information about it, I explain ...

I already have my service generator for Retrofit and my interface, both in Java; aside I have my models for the answers and shipments only that those are in Kotlin.
When I use the @GET with my Kotlin models I do not have any problem, but when I add an @POST to my interface it gives me the following errors in my interface file:

error: <identifier> expected  
error: ’;’ expected

and after that it will not let me compile until I remove my @POST from the interface, this is my interface:

public interface Prueba {  
  @POST("/v1/posts")  
  public Call<MyResponse> newPackage(@Body Package package);  
}

this is my model for Package in Kotlin:

data class Package(  
  @SerializedName("label") @Expose var label: String,  
  @SerializedName("name") @Expose var name: String  
) {}

I have already reviewed the Retrofit documentation and nothing seems to be wrong, I do not know if I can give those errors and I can not find information about it, so I'm not sure if I do something wrong or what happens.
Thanks in advance to anyone who can help me or give some light about this.

Status update

Okay, yesterday I continued adding several PUT to my interface and those are working well, so I tried to try again but changing my body model POST for one similar to my body have PUT, so now the model stayed like this:

class Package(  
  val label: String,  
  val name: String  
) {}

The issue is that now I get the following error:
    parameter name expected

I do not know what that means and I do not find anything about it either, it's worth mentioning that regardless of whether my second field is called name or fido or foo or whatever the error does not change, it keeps saying the same thing. I hope I can solve this soon

    
asked by Paris N. Salguero 09.07.2017 в 23:52
source

1 answer

0

I already managed to solve the problem, it was all because for some reason Android Studio removed my import from my Body class, I do not understand why it was eliminated but deactivating the auto imports on fly, adding the import again, compiling and re-activating auto imports no longer gives the problem again.
Thanks to everyone who commented.

    
answered by 11.07.2017 в 04:34