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;
}
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);
}
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);
}
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);
}
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("]");
}
Aggregations