本文整理匯總了Java中org.codehaus.jackson.JsonToken.isScalarValue方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonToken.isScalarValue方法的具體用法?Java JsonToken.isScalarValue怎麽用?Java JsonToken.isScalarValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.JsonToken
的用法示例。
在下文中一共展示了JsonToken.isScalarValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialize
import org.codehaus.jackson.JsonToken; //導入方法依賴的package包/類
public String deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
JsonToken localJsonToken = paramJsonParser.getCurrentToken();
if (localJsonToken == JsonToken.VALUE_STRING)
return paramJsonParser.getText();
if (localJsonToken == JsonToken.VALUE_EMBEDDED_OBJECT)
{
Object localObject = paramJsonParser.getEmbeddedObject();
if (localObject == null)
return null;
if ((localObject instanceof byte[]))
return Base64Variants.getDefaultVariant().encode((byte[])(byte[])localObject, false);
return localObject.toString();
}
if (localJsonToken.isScalarValue())
return paramJsonParser.getText();
throw paramDeserializationContext.mappingException(this._valueClass);
}
示例2: injectDefaultValueIfAvailable
import org.codehaus.jackson.JsonToken; //導入方法依賴的package包/類
private void injectDefaultValueIfAvailable(final JsonParser in, String fieldName) throws IOException {
Field field = findField(schema, fieldName);
if (field == null) {
throw new AvroTypeException("Expected field name not found: " + fieldName);
}
JsonNode defVal = field.defaultValue();
if (defVal == null) {
throw new AvroTypeException("Expected field name not found: " + fieldName);
}
List<JsonElement> result = new ArrayList<>(2);
JsonParser traverse = defVal.traverse();
JsonToken nextToken;
while ((nextToken = traverse.nextToken()) != null) {
if (nextToken.isScalarValue()) {
result.add(new JsonElement(nextToken, traverse.getText()));
} else {
result.add(new JsonElement(nextToken));
}
}
result.add(NULL_JSON_ELEMENT);
if (currentReorderBuffer == null) {
currentReorderBuffer = new ReorderBuffer();
}
currentReorderBuffer.origParser = in;
this.in = makeParser(result);
}
示例3: deserialize
import org.codehaus.jackson.JsonToken; //導入方法依賴的package包/類
@Override
public Set<String> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
JsonProcessingException {
JsonToken token = jp.getCurrentToken();
if (token.isScalarValue()) {
String list = jp.getText();
list = list.replaceAll("\\s+", ",");
return new LinkedHashSet<String>(Arrays.asList(StringUtils.commaDelimitedListToStringArray(list)));
}
return jp.readValueAs(new TypeReference<Set<String>>() {
});
}
示例4: readFieldAsString
import org.codehaus.jackson.JsonToken; //導入方法依賴的package包/類
public static String readFieldAsString(String text,
JsonParser p,
ResourceFieldSchema field)
throws IOException {
JsonToken tok = p.getCurrentToken();
if (tok == JsonToken.VALUE_NULL) return null;
if (tok.isScalarValue()) {
return p.getText();
} else {
JsonToken start, end;
int startPos, endPos, nesting;
if (tok == JsonToken.START_OBJECT) {
start = JsonToken.START_OBJECT;
end = JsonToken.END_OBJECT;
} else if (tok == JsonToken.START_ARRAY) {
start = JsonToken.START_ARRAY;
end = JsonToken.END_ARRAY;
} else {
// Should never happen
throw new IllegalArgumentException(
"Bad bytearray/chararray field: expected scalar value or start object/array token, but found " + tok.asString());
}
// skip to the end of this object/array
// The parser's reported column number depends on whitespace
// and other weirdness I don't quite get, so the simplest way
// that I could find to handle nested structures is to use
// this "rewind" method
p.skipChildren();
endPos = p.getCurrentLocation().getColumnNr();
startPos = endPos;
if (end == JsonToken.END_OBJECT) {
while (text.charAt(endPos) != '}' && endPos > 0) endPos--;
nesting = 1;
startPos = endPos;
while (nesting > 0 && startPos > 0) {
startPos--;
if (text.charAt(startPos) == '}')
nesting++;
else if (text.charAt(startPos) == '{')
nesting--;
}
} else if (end == JsonToken.END_ARRAY) {
while (text.charAt(endPos) != ']' && endPos > 0) endPos--;
nesting = 1;
startPos = endPos;
while (nesting > 0 && startPos > 0) {
startPos--;
if (text.charAt(startPos) == ']')
nesting++;
else if (text.charAt(startPos) == '[')
nesting--;
}
}
return text.substring(startPos, endPos + 1);
}
}