Example usage for com.google.gwt.core.client JsonUtils escapeValue

List of usage examples for com.google.gwt.core.client JsonUtils escapeValue

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsonUtils escapeValue.

Prototype

public static native String escapeValue(String toEscape) ;

Source Link

Document

Returns a quoted, escaped JSON String.

Usage

From source file:org.rapla.rest.client.gwt.internal.impl.ser.PrimitiveArraySerializer.java

License:Apache License

public void printJson(final StringBuilder sb, final Character[] o) {
    sb.append('[');
    for (int i = 0, n = o.length; i < n; i++) {
        if (i > 0) {
            sb.append(',');
        }/*from  ww w  .  j av a  2s.  c  om*/
        if (o[i] != null) {
            sb.append(JsonUtils.escapeValue(String.valueOf(o[i])));
        } else
            sb.append(JsonSerializer.JS_NULL);
    }
    sb.append(']');
}

From source file:org.rapla.rest.client.gwt.internal.impl.ser.StringMapSerializer.java

License:Apache License

@Override
public void printJson(final StringBuilder sb, final Map<String, V> o) {
    sb.append('{');
    boolean first = true;
    for (final Map.Entry<String, V> e : o.entrySet()) {
        if (first) {
            first = false;//from w  w w .j  a v a  2s.com
        } else {
            sb.append(',');
        }
        sb.append(JsonUtils.escapeValue(e.getKey()));
        sb.append(':');
        encode(sb, valueSerializer.get(), e.getValue());
    }
    sb.append('}');
}

From source file:org.rapla.rest.gwtjsonrpc.client.impl.JsonSerializer.java

License:Apache License

/**
 * Utility function to convert a String to safe JSON text.
 * <p>//from   ww  w.java  2 s  . c  o  m
 * For example, if <code>val = "b\nb"</code> this method returns the value
 * <code>"\"b\\nb\""</code>.
 * <p>
 * Typically called by {@link #printJson(StringBuilder, Object)}, or through
 * {@link JavaLangString_JsonSerializer}.
 * 
 * @param val string text requiring escaping support. Must not be null.
 * @return a JSON literal text value, surrounded with double quotes.
 * @deprecated Use {@link JsonUtils#escapeValue(String)}
 */
@Deprecated
public static final String escapeString(String val) {
    return JsonUtils.escapeValue(val);
}

From source file:org.rapla.rest.gwtjsonrpc.client.impl.ser.JavaLangString_JsonSerializer.java

License:Apache License

@Override
public void printJson(final StringBuilder sb, final java.lang.String o) {
    sb.append(JsonUtils.escapeValue(o));
}

From source file:org.rapla.rest.gwtjsonrpc.client.impl.ser.StringMapSerializer.java

License:Apache License

@Override
public void printJson(final StringBuilder sb, final java.util.Map<String, V> o) {
    sb.append('{');
    boolean first = true;
    for (final Map.Entry<String, V> e : o.entrySet()) {
        if (first) {
            first = false;//  w  w  w.  j  a  va  2s  .co m
        } else {
            sb.append(',');
        }
        sb.append(JsonUtils.escapeValue(e.getKey()));
        sb.append(':');
        encode(sb, valueSerializer.get(), e.getValue());
    }
    sb.append('}');
}

From source file:org.zoxweb.client.data.JSONClientUtil.java

License:Apache License

public static String toString(JSONObject jobj) {
    StringBuilder sb = new StringBuilder("{");
    boolean first = true;
    String[] keys = jobj.keySet().toArray(new String[0]);
    for (String key : keys) {
        if (first) {
            first = false;//from  w w  w .j  av  a  2  s .c  o  m
        } else {
            sb.append(",");
        }
        sb.append(JsonUtils.escapeValue(key));
        sb.append(":");
        sb.append(jobj.get(key));
    }
    sb.append("}");
    return sb.toString();
}