Announcement Announcement Module
No announcement yet.
Escaping '&' in args of restTemplate.getForObject Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Escaping '&' in args of restTemplate.getForObject

    Hi there,

    I'm having trouble when I use '&' in a args parameter for restTemplate.getForObject. The RestTemplate seems to think it is another parameter in the url and thus cuts the String I'm posting from the '&'.

    Here is my example:

    Map<String, String> vars = new HashMap<String, String>();
    vars.put(CommonWebConstants.RPXSocialNetworking.AP I_KEY,"xxxxxxxxx")

    vars.put(CommonWebConstants.RPXSocialNetworking.ID ENTIFIER,"");
    vars.put(CommonWebConstants.RPXSocialNetworking.ST ATUS, "trying to escape & so doesn't cut off post");

    String result = restTemplate.getForObject("{apiKey}&identifier={identifier} &status={status}",String.class, vars);

    My problem is with the status.. this could be any text typed by the user and may include '&' in the text. The result of this is 'trying to escape '. It sees the '&' as a new parameter and truncates the rest. I have tried escaping the '&' with &amp; and %26 but these just print out.

    Please help!!



  • #2

    I've now resolved this issue by using the getForObject method that takes a URI - this one doesn't do any encoding and so I can encode the text myself and handles the ampersand.