1

I am creating a string of data class for our API optimization like this

data class ex:

@MyAnnotation
data class Cast( 
     @Json(name = "cast_id") 
     val castId: Int, 

     val name: String, 

     @Json(name = "profile_path") 
     val profilePath: String? 
)

wanted result:

{"cast_id":1, "name":1, "profile_path":1}

but currently able to generate it

"{"castId":1, "name":1, "profilePath":1}"

I want access @JSON (or @SerializedName) annotation and its value, how do I get it?

then Using Kotlin poet to create class with this string init.

Aniket Bhoite
  • 116
  • 1
  • 6
  • Could you please add more details? What JSON serializer are you using? If you need to change naming strategy using serialization library e.g. Jackson, source code generation is an overkill. – geobreze Apr 26 '21 at 10:25
  • This not for serialization, This string will be used as a query param in API. I also want make it flexible to support both Moshi and GSON. – Aniket Bhoite Apr 26 '21 at 14:35

0 Answers0