本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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?
}
}
示例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));
}
示例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;
}
示例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);
}
}
示例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);
}
示例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)) + "\"" +
"}" +
"]" +
"}" +
"}";
}
示例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();
}
示例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();
}
示例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));
}
示例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);
}
示例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));
}
示例15: applyJsonQuoting
import com.fasterxml.jackson.core.io.JsonStringEncoder; //导入依赖的package包/类
@Override
protected char[] applyJsonQuoting(String content) {
return JsonStringEncoder.getInstance().quoteAsString(content);
}