本文整理汇总了Java中com.fasterxml.jackson.core.io.JsonStringEncoder.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java JsonStringEncoder.getInstance方法的具体用法?Java JsonStringEncoder.getInstance怎么用?Java JsonStringEncoder.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.io.JsonStringEncoder
的用法示例。
在下文中一共展示了JsonStringEncoder.getInstance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCreateTestQueryBuilder
import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入方法依赖的package包/类
@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);
}
示例2: getRandomValueForFieldName
import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入方法依赖的package包/类
/**
* 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;
}
示例3: buildJsonQuery
import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入方法依赖的package包/类
public static String buildJsonQuery(String queryString, long id) {
JsonStringEncoder encoder = JsonStringEncoder.getInstance();
return "{" +
"\"id\": " + String.valueOf(id) + "," +
"\"query\": {" +
"\"and\": [" +
"{" +
"\"field\": \"textField\"," +
"\"condition\": \"match\"," +
"\"value\": \"" + new String(encoder.quoteAsString(queryString)) + "\"" +
"}" +
"]" +
"}" +
"}";
}
示例4: buildDoc
import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入方法依赖的package包/类
public static Document buildDoc(DocumentBuilder builder, String query) {
JsonStringEncoder encoder = JsonStringEncoder.getInstance();
String json = "{\"textField\": \"" + new String(encoder.quoteAsString(query)) + "\"}";
try {
return builder.build(json);
} catch (MalformedDocumentException e) {
e.printStackTrace();
}
return new Document();
}
示例5: toJson
import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入方法依赖的package包/类
/**
* JSON representation of this object.
* If cause is null then it is not written and
* if errorCode <= 0 then it is not written.
* @return JSON string
*/
public String toJson()
{
JsonStringEncoder encoder = JsonStringEncoder.getInstance();
StringBuilder builder = new StringBuilder();
builder.append('{');
boolean needComma = true;
if (m_Message != null)
{
char [] message = encoder.quoteAsString(m_Message.toString());
builder.append("\n \"message\" : \"").append(message).append('"').append(',');
needComma = false;
}
if (m_ErrorCode != null)
{
builder.append("\n \"errorCode\" : ").append(m_ErrorCode.getValueString());
needComma = true;
}
if (m_Cause != null)
{
if (needComma)
{
builder.append(',');
}
char [] cause = encoder.quoteAsString(m_Cause.toString());
builder.append("\n \"cause\" : \"").append(cause).append('"');
}
builder.append("\n}\n");
return builder.toString();
}
示例6: doCreateTestQueryBuilder
import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入方法依赖的package包/类
@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);
}
示例7: escapeText
import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入方法依赖的package包/类
public static String escapeText(String text) {
final JsonStringEncoder enc = JsonStringEncoder.getInstance();
return new String(enc.quoteAsString(text));
}