last day (16 days later) » 

12:29
0
A: How to remove white space from json object key in retrofit?

Lakhwinder SinghTry using the benefits of getter function public String getTitle() { return Title.trim(); } as same with others as well. try to use this, if this will not help let m know in the comment, we'll find another solution

I tried this but this fixes only for values but not for key.
Also i tried this way too. public String getPoster() { return Poster == null ? Uri.parse("R.drawable.ic_launcher_background").toString() : Poster.trim(); }
why do you need it to trim keys, values are useful not keys. Is there anything specific?
I used Title.trim but I am getting error as Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference
No. Actually I need to acces the url from the Poster but it has two different Poster that's the problem.
what did you mean by that, is Movie().getPoster() not returning you the URL
it's actually a string. Let me simplify and say. { "movies": { "Title": "Avengers:Age of Ultron ", "Year": "2015 ", }, { "Title": "TheAvengers ", "Year": "2012 ", "Poster": "[m.media-amazon.com/images/M/… ", }, { "Title": "Sleepless ", "Year": "2017 ", "Poster ": "m.media-amazon.com/images/M/… " }]}
In the above json structure, first contains no poster field, second contains "Poster" field and third contains "Poster " fields. Third has white space but second and third Poster has url. But I can use only one Poster field.
I tried @Joop's solution but I am not able to use two fields at a time @SerializedName(value="Poster", alternate={"Poster ", "Poster"})
12:29
what do you mean by two fields at a time
@Lakhwinder
{
"movies": [{
"Title": "Avengers:Age of Ultron ",
"Year": "2015 ",
}, {
"Title": "TheAvengers ",
"Year": "2012 ",
"Poster": "https://m.media-amazon.com/images/M/MV5BNDYxNjQyMjAtNTdiOS00NGYwLWFmNTAtNThmYjU5ZGI2YTI1XkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_SX300.jpg ",
}, {
"Title": "Sleepless ",
"Year": "2017 ",
"Poster ": "https://m.media-amazon.com/images/M/MV5BNjEwMDAyOTM4OV5BMl5BanBnXkFtZTgwMzc4MjMyMDI@._V1_SX300.jpg "
}]}
yes i saw that
now what do you want to achieve
in this structure, Poster field contains different format structure. So any one only, I am able to get
if I use this
@SerializedName("Poster ")
private String Poster; // I am able to get only third one
12:31
Value does not matter, keys must be same
@SerializedName("Poster") //no whitespace
private String Poster; // I am able to get only second one
oh k
so how to achieve this then?
Ohh i saw the issue
key has a whitespace in third one
but backend team is not solving by giving same key by removing whitespace
yes
Buddy its clearly problem of backend
they have to resolve this by their own
and i dont understand why they are not solving it
:( but they are not doing. Escalating to do on your side.
12:33
but why
its not a standard
although we can solve it
but its off the standards
there must be a solid reason
because it's already done. so they are not touching the code.
i this api is used in any other old project?
but still that is not the issue
no
it may have been used
i referred.
12:35
but they have to solve it
or i need to justify it's impossible in android side. But my architech is saying u can by gson. (but never given solution, that's different case)
its not impossible
just you dont need to,because its server issue
ok leave
lets find the solution
okay
@LakhwinderSingh i seen this too but I am clueless where exactly i need to use. stackoverflow.com/a/30228588/3500826
in this case, String newKey = currentKey.replaceAll(" ", "_"); //replaced with underscore. I can replace with "". But problem is where I need to use.
try to print response.body()?.string()
we can go one by one
first if that statement prints the result
then we convert result in to our JSON object
then to your POJO class by changing the values
try above
okay
12:48
i am leaving for the day
message you in the morning if you get no success
we'll try to find a different approch
there are plenty of ways to doing it
okay sure. Take care. Bye. Catch you tomorrow.
b/w when i print the response, i get as
responseResponse{protocol=http/1.1, code=200, message=OK, url=api.myjson.com/bins/18buhu}
sorry...i left body.toString
when i used Log.e("responseRetrofit","response"+response.body().toString());, in this case, it prints as
E/responseRetrofit: responsemovie.demo.DataModel.MovieResponse@2d1371b
and i tried printing like this too
Log.e("responseRetrofit => ",new Gson().toJson(response));
but this is displaying only the specified field.
if i specified as @SerializedName("Poster ")
private String Poster;
based on this, it's displaying..and "Poster" is not displaying

  last day (16 days later) »