mercredi 15 avril 2015

JSON Object as @RequestBody on Spring 4.16

So i have this android application that send jsonObject for a jsonObjectRequest (I'm using volley) with POST method. The JSON file was sent but the server (this is where i'm using Spring btw) is not responding. The code pretty much like these.


Android Code:



JSONObject jsonObject = new JSONObject(data);

final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
userToken = response.getString(TAG_TOKEN);
// blablabla


Server Code:



@RestController
@RequestMapping("/auth/")
public class AuthController {

String userEmail;
String userPassword;

@RequestMapping(value = "/login", method = RequestMethod.POST)
public LoginResponse loginResponse(@RequestBody Auth auth){

userEmail = auth.getEmail();
userPassword = auth.getPassword();
// blablabla


Auth Object:



public class Auth {

private String email;
private String password;

// blablabla


It seems like the server didn't receive the JsonObject from the android client correctly. (The server is able to send JSON to android client perfectly in another case, though). I'm using spring-4.16, jackson-core, jackson-annotation, jackson-databind (2.2.2). Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire