use of com.fasterxml.jackson.core.io.JsonStringEncoder in project elasticsearch by elastic.
the class AbstractQueryTestCase method getRandomValueForFieldName.
/**
* create a random value for either {@link AbstractQueryTestCase#BOOLEAN_FIELD_NAME}, {@link AbstractQueryTestCase#INT_FIELD_NAME},
* {@link AbstractQueryTestCase#DOUBLE_FIELD_NAME}, {@link AbstractQueryTestCase#STRING_FIELD_NAME} or
* {@link AbstractQueryTestCase#DATE_FIELD_NAME}, or a String value by default
*/
protected static Object getRandomValueForFieldName(String fieldName) {
Object value;
switch(fieldName) {
case STRING_FIELD_NAME:
if (rarely()) {
// unicode in 10% cases
JsonStringEncoder encoder = JsonStringEncoder.getInstance();
value = new String(encoder.quoteAsString(randomUnicodeOfLength(10)));
} else {
value = randomAsciiOfLengthBetween(1, 10);
}
break;
case INT_FIELD_NAME:
value = randomIntBetween(0, 10);
break;
case DOUBLE_FIELD_NAME:
value = 1 + randomDouble() * 9;
break;
case BOOLEAN_FIELD_NAME:
value = randomBoolean();
break;
case DATE_FIELD_NAME:
value = new DateTime(System.currentTimeMillis(), DateTimeZone.UTC).toString();
break;
default:
value = randomAsciiOfLengthBetween(1, 10);
}
return value;
}
use of com.fasterxml.jackson.core.io.JsonStringEncoder in project elasticsearch by elastic.
the class SpanTermQueryBuilderTests method doCreateTestQueryBuilder.
@Override
protected SpanTermQueryBuilder doCreateTestQueryBuilder() {
String fieldName = null;
Object value;
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)));
}
if (fieldName == null) {
fieldName = randomAsciiOfLengthBetween(1, 10);
}
return createQueryBuilder(fieldName, value);
}
use of com.fasterxml.jackson.core.io.JsonStringEncoder in project jackson-core by FasterXML.
the class BufferRecyclers method getJsonStringEncoder.
public static JsonStringEncoder getJsonStringEncoder() {
SoftReference<JsonStringEncoder> ref = _encoderRef.get();
JsonStringEncoder enc = (ref == null) ? null : ref.get();
if (enc == null) {
enc = new JsonStringEncoder();
_encoderRef.set(new SoftReference<JsonStringEncoder>(enc));
}
return enc;
}
use of com.fasterxml.jackson.core.io.JsonStringEncoder in project vespa by vespa-engine.
the class JsonReaderTestCase method testRaw.
@Test
public final void testRaw() throws IOException {
String stuff = new String(new JsonStringEncoder().quoteAsString(new Base64().encodeToString(Utf8.toBytes("smoketest"))));
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testraw::whee\"," + " \"fields\": { \"actualraw\": \"" + stuff + "\"" + " }}"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo parseInfo = r.parseDocument().get();
DocumentType docType = r.readDocumentType(parseInfo.documentId);
DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
Document doc = put.getDocument();
FieldValue f = doc.getFieldValue(doc.getField("actualraw"));
assertSame(Raw.class, f.getClass());
Raw s = (Raw) f;
ByteBuffer b = s.getByteBuffer();
assertEquals("smoketest", Utf8.toString(b));
}
use of com.fasterxml.jackson.core.io.JsonStringEncoder in project XRTB by benmfaul.
the class TestEncoding method main.
public static void main(String[] args) {
JsonStringEncoder encoder = JsonStringEncoder.getInstance();
String test = "This is \\\\\" a test";
char[] output = encoder.quoteAsString(test);
String end = new String(output);
System.out.println(test);
;
System.out.println(end);
;
}
Aggregations