tl;dr I will keep this short at the top and put most of my models and code needed at the bottom.
I have the following String:
String engineer_request = "<GetStuff Revision=\"1.1.0\"> \n" + "<RequestedProperties> \n" + "<Item>Key</Item> \n" + "<Item>ID</Item> \n" + "<Item>Manager</Item> \n" + "<Item>PhoneNumber</Item> \n" + "<Item>EmailAddress</Item>\n" + "<Item>MobileLoginID</Item>\n" + "<Item>Name</Item> \n" + "<Item>Active</Item> \n" + "</RequestedProperties> \n" + "</GetStuff>\n";
I'm trying to create an object to send to my API via Retrofit. The problem is that I can't seem to get the structure right. My retrofit service call sends and the logger spits back:
<myRequest> <GetStuff Revision=\"1.1.0\"> <RequestedProperties> <Item>Key</Item> </RequestedProperties> </GetStuff Revision=\"1.1.0\"> </myRequest>
But I need it to spit back this:
<GetStuff Revision=\"1.1.0\"> <RequestedProperties> <Item>Key</Item> <Item>ID</Item> <Item>Manager</Item> <Item>PhoneNumber</Item> <Item>EmailAddress</Item> <Item>MobileLoginID</Item> <Item>Name</Item> <Item>Active</Item> </RequestedProperties> </GetStuff>
If you know how to accomplish this quick and easy then read no further and go ahead and let me know. If you need more information please see below and I will explain in detail.
So far this is my code:
public MyRequest getXML() { MyRequest myXMLRequest = new MyRequest(); RequestRoot requestRoot = new RequestRoot(); RequestedProperties requestedProperties = new RequestedProperties(); requestedProperties.setItem("Key"); requestRoot.setRequest(requestedProperties); myXMLRequest.setRequestRoot(requestRoot); return myXMLRequest; }
and here are my models
MyRequest
public class MyRequest { public MyRequest() {} @Element(name = "GetStuff Revision=\"1.1.0\"") RequestRoot requestRoot; public void setRequestRoot(RequestRoot requestRoot) { this.requestRoot = requestRoot; } }
RequestRoot
public class RequestRoot { @Root(name = "GetStuff Revision=\"1.1.0\"") public RequestRoot() {} @Element(name = "RequestedProperties") RequestedProperties requestedProperties; public void setRequest(RequestedProperties requestedProperties) { this.requestedProperties = requestedProperties; } }
RequestedProperties
public class RequestedProperties { @Root(name = "RequestedProperties") public RequestedProperties() {} @Element(name = "Item") String item; public void setItem(String item) { this.item = item; } }
Then my service call
@POST("/services/stuff") Call<Response> getStuff(@Body MyRequest myRequest);
Any help is much appreciated. I've been at this for a while and I cant seem to figure out something that should be fairly straight forward. I'm pretty sure I'm butchering this, but I could be wrong. Thanks
No comments:
Post a Comment