Re: [android-developers]
I have the following return my webservice created in ruby on rails--{"created_at":"2013-08-24T02:45:13Z","datebirth":null,"email":"email@gmail.com","firstname":"Ricardo","gender":null,"id":11,"lastname":null,"modelphone":null,"password":null,"password_confirmation":null,"picture":null,"token":"98e58617a9beb77c71de20b3545550e4","typeos":null,"updated_at":"2013-08-25T20:45:25Z"}
This return I'm typing the curl in the console like this:
curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://localhost:3000/api/v1/sessions.json -d "{\"user\":{\"email\":\"email@gmail.com\",\"password\":\"secret1234\"}}"
and I also have the same return on Android! I'm using AndroidAnnotations and created the code that calls the webservice
@Background
void login(UserWrapper userWrapper){
try {
//Acessa o webservice através de rest passando o objeto UserWrapper que tem o Objeto User
JsonObject json = userRestClient.login(userWrapper);
Gson gson = new Gson();
userWrapper = gson.fromJson(json, UserWrapper.class);
sucessLogin(userWrapper);
} catch (RestClientException e) {
errorLogin();
}
}
But I am getting the following error
08-24 18:34:19.420: E/LoginActivity_(11373): com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING
My class is as follows restclient
@Rest(rootUrl="http://192.168.1.100:3000", converters={GsonHttpMessageConverter.class}) @Accept(MediaType.APPLICATION_JSON) public interface UserRestClient {@Post("/api/v1/registrations")
UserWrapper addUser(UserWrapper user);
@Post("/api/v1/sessions.json")
JsonObject login(UserWrapper user);
@Get("/users/{id}.json")
JsonObject edit(int id);
@Put("/users/{id}")
void update(User user, int id);
@Post("/user")
void recoverPassWordUser(String email);
I know that the return is a String from my server, but I need to get a JSONObject. I also know I need to use a parse, so I made the following way by changing my code
String json = userRestClient.login(userWrapper);JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(json).getAsJsonObject();
Gson gson = new Gson();
userWrapper = gson.fromJson(jsonObject, UserWrapper.class);
sucessLogin(userWrapper);
But I get the error the following error:
08-25 18:31:17.945: E/LoginActivity_(13266): org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 2; nested exception is com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 2When I change to receive a JSONObject error says that is a String, when I change a String to receive the error says that is a JSONObject.
Help-me
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Warm Regards,
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home