1

Is there a method to make JAX-RS call the Java equivalent of Javascript's encodeURI on the return? For example, let's say I have this class:

public Class MyResponse {
 public String greeting;
}

And this sample method:

@GET
@Path("response")
public MyResponse getResponse {
 MyResponse rtn = new MyResponse();
 rtn.greeting = "<b>Hello!</b>";
 return rtn;
}

Normally this would return the following JSON:

{
 greeting: "<b>Hello!</b>"
}

I would like a cross-cutting way to instead have the following returned:

{
 greeting: "%3Cb%3EHello!%3C/b%3E"
}

By cross-cutting I mean I don't want to have to hand-specify which fields to encode -- I would like all String fields to get this treatment.

sean
  • 2,560
  • 3
  • 18
  • 21

1 Answers1

0

May be you can use URLEncoder, which encodes given string.

Sajan Chandran
  • 11,287
  • 3
  • 29
  • 38
  • This doesn't appear to answer the question, which was how this operation can be applied to all fields on an Object automatically. – MrLore May 29 '14 at 01:39