当前位置: 首页>>代码示例>>Java>>正文


Java JsonStringEncoder.getInstance方法代码示例

本文整理汇总了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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:SpanTermQueryBuilderTests.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:AbstractQueryTestCase.java

示例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)) + "\"" +
            "}" +
            "]" +
            "}" +
            "}";
}
 
开发者ID:dbasedow,项目名称:prospecter,代码行数:16,代码来源:Application.java

示例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();
}
 
开发者ID:dbasedow,项目名称:prospecter,代码行数:11,代码来源:Application.java

示例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();
}
 
开发者ID:prelert,项目名称:engine-java,代码行数:42,代码来源:ApiError.java

示例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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:TermQueryBuilderTests.java

示例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));
}
 
开发者ID:line,项目名称:centraldogma,代码行数:5,代码来源:Jackson.java


注:本文中的com.fasterxml.jackson.core.io.JsonStringEncoder.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。