Search in sources :

Example 1 with JsonStringEncoder

use of com.fasterxml.jackson.core.io.JsonStringEncoder in project elasticsearch by elastic.

the class AbstractTermQueryTestCase method getAlternateVersions.

@Override
protected Map<String, QB> getAlternateVersions() {
    HashMap<String, QB> alternateVersions = new HashMap<>();
    QB tempQuery = createTestQueryBuilder();
    QB testQuery = createQueryBuilder(tempQuery.fieldName(), tempQuery.value());
    boolean isString = testQuery.value() instanceof String;
    Object value;
    if (isString) {
        JsonStringEncoder encoder = JsonStringEncoder.getInstance();
        value = "\"" + new String(encoder.quoteAsString((String) testQuery.value())) + "\"";
    } else {
        value = testQuery.value();
    }
    String contentString = "{\n" + "    \"" + testQuery.getName() + "\" : {\n" + "        \"" + testQuery.fieldName() + "\" : " + value + "\n" + "    }\n" + "}";
    alternateVersions.put(contentString, testQuery);
    return alternateVersions;
}
Also used : HashMap(java.util.HashMap) JsonStringEncoder(com.fasterxml.jackson.core.io.JsonStringEncoder)

Example 2 with JsonStringEncoder

use of com.fasterxml.jackson.core.io.JsonStringEncoder in project elasticsearch by elastic.

the class TermQueryBuilderTests method doCreateTestQueryBuilder.

@Override
protected TermQueryBuilder doCreateTestQueryBuilder() {
    String fieldName = null;
    Object value;
    switch(randomIntBetween(0, 3)) {
        case 0:
            if (randomBoolean()) {
                fieldName = BOOLEAN_FIELD_NAME;
            }
            value = randomBoolean();
            break;
        case 1:
            if (randomBoolean()) {
                fieldName = STRING_FIELD_NAME;
            }
            if (frequently()) {
                value = randomAsciiOfLengthBetween(1, 10);
            } else {
                // generate unicode string in 10% of cases
                JsonStringEncoder encoder = JsonStringEncoder.getInstance();
                value = new String(encoder.quoteAsString(randomUnicodeOfLength(10)));
            }
            break;
        case 2:
            if (randomBoolean()) {
                fieldName = INT_FIELD_NAME;
            }
            value = randomInt(10000);
            break;
        case 3:
            if (randomBoolean()) {
                fieldName = DOUBLE_FIELD_NAME;
            }
            value = randomDouble();
            break;
        default:
            throw new UnsupportedOperationException();
    }
    if (fieldName == null) {
        fieldName = randomAsciiOfLengthBetween(1, 10);
    }
    return createQueryBuilder(fieldName, value);
}
Also used : JsonStringEncoder(com.fasterxml.jackson.core.io.JsonStringEncoder)

Example 3 with JsonStringEncoder

use of com.fasterxml.jackson.core.io.JsonStringEncoder in project vespa by vespa-engine.

the class JsonWriterTestCase method rawTest.

@Test
public final void rawTest() throws IOException {
    String payload = new String(new JsonStringEncoder().quoteAsString(new Base64().encodeToString(Utf8.toBytes("smoketest"))));
    String docId = "id:unittest:testraw::whee";
    String fields = "{ \"actualraw\": \"" + payload + "\"" + " }";
    roundTripEquality(docId, fields);
}
Also used : Base64(org.apache.commons.codec.binary.Base64) JsonStringEncoder(com.fasterxml.jackson.core.io.JsonStringEncoder) Test(org.junit.Test)

Example 4 with JsonStringEncoder

use of com.fasterxml.jackson.core.io.JsonStringEncoder in project XRTB by benmfaul.

the class Creative method encodeUrl.

/**
 * Does the HTTP encoding for the forward url and image url. The bid will
 * use the encoded form.
 */
void encodeUrl() {
    MacroProcessing.findMacros(macros, forwardurl);
    MacroProcessing.findMacros(macros, imageurl);
    if (w != null) {
        if (dimensions == null)
            dimensions = new Dimensions();
        Dimension d = new Dimension(w, h);
        dimensions.add(d);
    }
    /*
		 * Encode JavaScript tags. Redis <script src=\"a = 100\"> will be
		 * interpeted as <script src="a=100"> In the ADM, this will cause
		 * parsing errors. It must be encoded to produce: <script src=\"a=100\">
		 */
    if (forwardurl != null) {
        JsonStringEncoder encoder = JsonStringEncoder.getInstance();
        char[] output = encoder.quoteAsString(forwardurl);
        forwardurl = new String(output);
    }
    /*if (forwardurl != null) {
			if (forwardurl.contains("<script") || forwardurl.contains("<SCRIPT")) {
				if (forwardurl.contains("\"") && (forwardurl.contains("\\\"") == false)) { 
					forwardurl = forwardurl.replaceAll("\"", "\\\\\"");
				}
			}
		}*/
    encodedFurl = URIEncoder.myUri(forwardurl);
    encodedIurl = URIEncoder.myUri(imageurl);
    if (adm != null && adm.size() > 0) {
        String s = "";
        for (String ss : adm) {
            s += ss;
        }
        unencodedAdm = s.replaceAll("\r\n", "");
        // unencodedAdm = unencodedAdm.replaceAll("\"", "\\\\\"");
        JsonStringEncoder encoder = JsonStringEncoder.getInstance();
        char[] output = encoder.quoteAsString(unencodedAdm);
        unencodedAdm = new String(output);
        MacroProcessing.findMacros(macros, unencodedAdm);
        encodedAdm = URIEncoder.myUri(s);
    }
    // strW = Integer.toString(w);
    // strH = Integer.toString(h);
    strPrice = Double.toString(price);
}
Also used : JsonStringEncoder(com.fasterxml.jackson.core.io.JsonStringEncoder)

Example 5 with JsonStringEncoder

use of com.fasterxml.jackson.core.io.JsonStringEncoder in project zookeeper by apache.

the class SnapshotFormatter method printSnapshotJson.

private void printSnapshotJson(final DataTree dataTree) {
    JsonStringEncoder encoder = JsonStringEncoder.getInstance();
    System.out.printf("[1,0,{\"progname\":\"SnapshotFormatter.java\",\"progver\":\"0.01\",\"timestamp\":%d}", System.currentTimeMillis());
    printZnodeJson(dataTree, "/", encoder);
    System.out.print("]");
}
Also used : JsonStringEncoder(com.fasterxml.jackson.core.io.JsonStringEncoder)

Aggregations

JsonStringEncoder (com.fasterxml.jackson.core.io.JsonStringEncoder)10 Base64 (org.apache.commons.codec.binary.Base64)2 Test (org.junit.Test)2 Document (com.yahoo.document.Document)1 DocumentPut (com.yahoo.document.DocumentPut)1 DocumentType (com.yahoo.document.DocumentType)1 FieldValue (com.yahoo.document.datatypes.FieldValue)1 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)1 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)1 Raw (com.yahoo.document.datatypes.Raw)1 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)1 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)1 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)1 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)1 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1