Search code examples
javaandroidkotlingsonretrofit

Add special character in keyname in Json, while sending json to api using retrofit Android


I am using retrofit for api call and Moshi, and for request one of key name is having a special character @ and when making the request its getting removed by Moshi or retrofit and getting missing key response from server is there any way to pass @ or special characters in keyname ?

@Json(name = "@Keyname") val Keyname: String,

Solution

  • for sending special character in keyname of a json we can use it like this using Moshi

    @field:Json(name = "@Keyname") val keyname: String,
    

    // it will create a json like this

    {
    "@keyname":"value"
    }