commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Grobmeier <grobme...@gmail.com>
Subject Re: [LANG] How to escape JSON data
Date Thu, 11 Apr 2013 10:40:40 GMT
On Wed, Apr 10, 2013 at 8:41 PM, Maurizio Cucchiara
<mcucchiara@apache.org> wrote:
> There are a lot of reasons which let me think that having inside the
> StringEscapeUtils class is a legitimate idea:
> 1. take a look at SEU's methods [2]
> 2. adding a new dependency, just for json escaping,  seems excessive to me.
> 3. Last but not least there is already an open issue [1], and FYI I
> have already submitted a patch.

I am using StringEscapeUtils for that task in my JSON lib:
https://github.com/grobmeier/jjson/blob/master/jjson/src/main/java/de/grobmeier/jjson/convert/JSONAnnotationEncoder.java

(line 274)

private void encodeString(String string, StringBuilder result, JSON
annotation) {
    if(string == null) {
            result.append(NULL);
        } else {
        result.append(QUOTE);
         result.append(StringEscapeUtils.escapeJava(string));
         result.append(QUOTE);
        }
    }

It works pretty well for me. Note, I am using it actually with Struts
2, I created a simple JSON plugin in the same repos.
If its of use, I am willing to contribute everything to whereever it makes sense

Cheers
Christian



>
> [1] https://issues.apache.org/jira/browse/LANG-797
> [2] http://commons.apache.org/proper/commons-lang//apidocs/org/apache/commons/lang3/StringEscapeUtils.html#method_summary
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>



--
http://www.grobmeier.de
https://www.timeandbill.de

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message