android - Retrofit POST with a json object containing parameters -



android - Retrofit POST with a json object containing parameters -

i'm using retrofit send post request server:

@post("/login") void login( @body user user ,callback<user> callback);

where user object has email , password fields.

checking logs, can see parameters sent format:

d/retrofit﹕{"email":"example@test.com","password":"asdfasdf"}

what need parameters sent this?

{"user" : {"email":"example@test.com","password":"asdfasdf"} }

edit: making right way, using custom jsonserializer:

public class customgsonadapter { public static class useradapter implements jsonserializer<user> { public jsonelement serialize(user user, type typeofsrc, jsonserializationcontext context) { gson gson = new gson(); jsonelement je = gson.tojsontree(user); jsonobject jo = new jsonobject(); jo.add("user", je); homecoming jo; } } }

and then, on api client builder:

public static restapiclient buildapiservice() { gson gson = new gsonbuilder() .setfieldnamingpolicy(fieldnamingpolicy.lower_case_with_underscores) .registertypeadapter(user.class, new customgsonadapter.useradapter()) .create(); restadapter restadapter = new restadapter.builder() .setendpoint(api_url) .setconverter(new gsonconverter(gson)) .build(); homecoming restadapter.create(mudamosapi.class); }

android json gson retrofit

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -