java - Converting POJO to protocol buffer request message -


instead of using relationship.relationshipgetrequest request , response. there way convert request/response pojo?

i've seen solution bit more complicated i'm looking for: converting protocol buffer pojo

i'm using retrofit , google protocol buffers.

what have:

public interface relationshipservice {      @post("/relation/get")     observable<relationships.relationshipgetresponse> getrelationship(             @body() relationship.relationshipgetrequest request     ); } 

what want use:

public interface relationshipservice {      @post("/relation/get")     observable<relationship> getrelationship(             @body() relationship request     ); } 

relationship:

public class relationship {     private long mrelationshipid;     private string mname;     // etc. 10 other properties.. } 

my request ends being request has built here..

mclient.createservice(relationshipservice.class).getrelationship(relationships.relationshipgetrequest.newbuilder().setrelationshipid(-1).build()).subscribeon(schedulers.newthread())         .observeon(androidschedulers.mainthread())         .subscribe(new subscriber<relationships.relationshipgetresponse>() {             @override             public void oncompleted() {              }              @override             public void onerror(throwable e) {                 timber.e(e, "error! " + e.getmessage());             }              @override             public void onnext(relationships.relationshipgetresponse relationship) {                  string output = relationsip.getrelationship().getname();                 timber.i(output);             }         }); 

you have write own adapters convert protobuff messages pojo instances. otherwise can try protostuff can use existing pojos schema. check this: https://github.com/anirbanroy88/services/tree/master/protostuff


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -