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


Java JsonToken.isScalarValue方法代码示例

本文整理汇总了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);
}
 
开发者ID:zhangjianying,项目名称:12306-android-Decompile,代码行数:20,代码来源:StdDeserializer.java

示例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);
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:30,代码来源:ExtendedJsonDecoder.java

示例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>>() {
	});
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:13,代码来源:BaseClientDetails.java

示例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);
    }
}
 
开发者ID:mortardata,项目名称:pig-json,代码行数:65,代码来源:JsonLoader.java


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