java - trim all String values in JsonNode -
i need trim string values
{ "startdate": "2015-06-29", "enddate": "2015-07-04", "category": "vip ", "name": " govind", age: 10, "place": " goa " } i doing by
jsonnode json = request().body().asjson(); classname cl = json.fromjson(json , classname.class); and trimming in setter of classname
suggest other approach because know not approach
if can confirm json not have quotes within values better performance i'd trimming on raw text rather parsed version:
val text = request.body.astext // regex explanation: // space followed asterisk means number of spaces // backward slash escapes following character val trimmed = text.map(_.replaceall(" *\" *", "\"")) import play.api.libs.json.json val json = json.parse(trimmed) java version:
import play.api.libs.json.*; string text = request().body().astext(); string trimmed = text.replaceall(" *\" *", "\""); jsvalue json = json.parse(trimmed);
Comments
Post a Comment