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


Java JsonStringEncoder类代码示例

本文整理汇总了Java中com.fasterxml.jackson.core.io.JsonStringEncoder的典型用法代码示例。如果您正苦于以下问题:Java JsonStringEncoder类的具体用法?Java JsonStringEncoder怎么用?Java JsonStringEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonStringEncoder类属于com.fasterxml.jackson.core.io包,在下文中一共展示了JsonStringEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: convertReturnedStringToRawJSON

import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
@Around("methods()")
public Object convertReturnedStringToRawJSON(ProceedingJoinPoint pjp) throws Throwable {

    checkMethodHasJsonRawValueAnnotation(pjp);

    String res = (String) pjp.proceed();

    if (!jsonValidator.isValidJsonString(res)) {
        JsonStringEncoder jsonStringEncoder = new JsonStringEncoder();
        StringBuilder sb = new StringBuilder();
        sb.append("\"").append(jsonStringEncoder.quoteAsString(res)).append("\"");
        res = sb.toString();
    }

    return res;
}
 
开发者ID:box,项目名称:mojito,代码行数:17,代码来源:JsonRawStringAspect.java

示例3: escapeJSONString

import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
/**
 * Escapes a text to be used for a JSON string value.
 * 
 * @param text the text to escape for JSON
 * @return the escaped text if not null
 */
public static String escapeJSONString(String text)
{
	if (text == null)
	{
		return null;
	}
	
	// using Jackson's string quote method
	char[] escapedChars = JsonStringEncoder.getInstance().quoteAsString(text);
	if (text.contentEquals(CharBuffer.wrap(escapedChars)))
	{
		// nothing changed
		return text;
	}
	
	return String.valueOf(escapedChars);
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:24,代码来源:JRStringUtil.java

示例4: writeValue

import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
private void writeValue(Object value)throws IOException {
	if (value != null) {
		if (
				value instanceof Number
						|| value instanceof Boolean
				)
		{
			writer.write(value.toString());
		} else if (value instanceof Date) {
			writer.write("\"");
			writer.write(isoDateFormat.format((Date)value));
			writer.write("\"");
		} else {
			writer.write("\"");
			writer.write(JsonStringEncoder.getInstance().quoteAsString(value.toString()));
			writer.write("\"");
		}
	} else {
		writer.write("null");  // FIXMEJSONMETA: how to treat null values?
	}
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:22,代码来源:JsonMetadataExporter.java

示例5: testRaw

import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
@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));
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:22,代码来源:JsonReaderTestCase.java

示例6: 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

示例7: encode

import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
@Override
public void encode(String value, Writer writer) {
    try {
        writer.write(JsonStringEncoder.getInstance().quoteAsString(value));
    } catch (IOException e) {
        throw new MustacheException("Failed to encode value: " + value);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:JsonEscapingMustacheFactory.java

示例8: rawTest

import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
@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);
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:11,代码来源:JsonWriterTestCase.java

示例9: 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

示例10: 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

示例11: 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

示例12: encode

import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
@Override
public void encode(String s, Writer writer) throws IOException {
    writer.write(JsonStringEncoder.getInstance().quoteAsString(s));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:CustomMustacheFactory.java

示例13: 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

示例14: 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

示例15: applyJsonQuoting

import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
@Override
protected char[] applyJsonQuoting(String content) {
	return JsonStringEncoder.getInstance().quoteAsString(content);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:Jackson2SockJsMessageCodec.java


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