當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonParser.nextToken方法代碼示例

本文整理匯總了Java中org.codehaus.jackson.JsonParser.nextToken方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.nextToken方法的具體用法?Java JsonParser.nextToken怎麽用?Java JsonParser.nextToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jackson.JsonParser的用法示例。


在下文中一共展示了JsonParser.nextToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readJsonEntry

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
/**
 * barファイルエントリからJSONファイルを読み込む.
 * @param <T> JSONMappedObject
 * @param inStream barファイルエントリのInputStream
 * @param entryName entryName
 * @param clazz clazz
 * @return JSONファイルから読み込んだオブジェクト
 * @throws IOException JSONファイル読み込みエラー
 */
public static <T> T readJsonEntry(
        InputStream inStream, String entryName, Class<T> clazz) throws IOException {
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    jp = f.createJsonParser(inStream);
    JsonToken token = jp.nextToken(); // JSONルート要素("{")
    Pattern formatPattern = Pattern.compile(".*/+(.*)");
    Matcher formatMatcher = formatPattern.matcher(entryName);
    String jsonName = formatMatcher.replaceAll("$1");
    T json = null;
    if (token == JsonToken.START_OBJECT) {
        try {
            json = mapper.readValue(jp, clazz);
        } catch (UnrecognizedPropertyException ex) {
            throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
        }
    } else {
        throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
    }
    return json;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:32,代碼來源:BarFileUtils.java

示例2: getRequestBody

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
/**
 * リクエストボディを解析してEventオブジェクトを取得する.
 * @param reader Http入力ストリーム
 * @return 解析したEventオブジェクト
 */
protected JSONEvent getRequestBody(final Reader reader) {
    JSONEvent event = null;
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    try {
        jp = f.createJsonParser(reader);
        JsonToken token = jp.nextToken(); // JSONルート要素("{")
        if (token == JsonToken.START_OBJECT) {
            event = mapper.readValue(jp, JSONEvent.class);
        } else {
            throw PersoniumCoreException.Event.JSON_PARSE_ERROR;
        }
    } catch (IOException e) {
        throw PersoniumCoreException.Event.JSON_PARSE_ERROR;
    }
    return event;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:24,代碼來源:EventResource.java

示例3: JsonFactory

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
/**
 * manifest.jsonのschema値がURL形式である場合trueが返卻されること.
 * @throws IOException IOException
 */
@SuppressWarnings("unchecked")
@Test
public void manifest_jsonのschema値がURL形式である場合trueが返卻されること() throws IOException {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "http://app1.example.com/");
    JsonParser jp = f.createJsonParser(json.toJSONString());
    ObjectMapper mapper = new ObjectMapper();
    jp.nextToken();

    JSONManifest manifest = mapper.readValue(jp, JSONManifest.class);

    assertTrue(manifest.checkSchema());
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:22,代碼來源:JSONManifestTest.java

示例4: JsonFactory

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
/**
 * bar_versionを指定しない場合に例外がスローされる.
 */
@Test
@SuppressWarnings({"unchecked" })
public void bar_versionを指定しない場合に例外がスローされる() {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "http://app1.example.com");

    try {
        JsonParser jp = f.createJsonParser(json.toJSONString());
        ObjectMapper mapper = new ObjectMapper();
        jp.nextToken();

        TestBarRunner testBarRunner = new TestBarRunner();
        testBarRunner.manifestJsonValidate(jp, mapper);
    } catch (PersoniumCoreException dce) {
        assertEquals(400, dce.getStatus());
        assertEquals("PR400-BI-0006", dce.getCode());
        return;
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
    fail("PersoniumCoreExceptionが返卻されない");
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:29,代碼來源:BarFileValidateTest.java

示例5: parse

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
public void parse(HttpRequest req) throws IOException {

      final JsonParser parser = jsonFactory.createJsonParser(
              new ChannelBufferInputStream(req.getContent()));

      parser.nextToken(); // Skip the wrapper

      while (parser.nextToken() != JsonToken.END_OBJECT) {

        final String metric = parser.getCurrentName();

        JsonToken currentToken = parser.nextToken();
        if (currentToken == JsonToken.START_OBJECT) {
          parseMetricObject(metric, parser);
        } else if (currentToken == JsonToken.START_ARRAY) {
          int illegalTokens = parseMetricArray(metric, parser);
          if(illegalTokens > 0) {
              logger.warn("{} illegal tokens encountered", illegalTokens);
          }
        } else {
          logger.warn("Illegal token: expected {} or {}, but was {}: {}",new Object[] {
                  JsonToken.START_OBJECT, JsonToken.START_ARRAY, currentToken, parser.getText()});
        }
      }
    }
 
開發者ID:yandex,項目名稱:opentsdb-flume,代碼行數:26,代碼來源:LegacyHttpSource.java

示例6: parseMetricArray

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private int parseMetricArray(String metric, JsonParser parser) throws IOException {
  JsonToken currentToken;
  int illegalTokens = 0;

  while ((currentToken = parser.nextToken()) != JsonToken.END_ARRAY) {

    if(!currentToken.equals(JsonToken.START_OBJECT)) {
        logger.warn("Illegal token: expected {}, but was {}: {}",
                new Object[] {JsonToken.START_OBJECT, currentToken, parser.getText()});
        illegalTokens++;
    } else {
        parseMetricObject(metric, parser);
    }

  }

  return illegalTokens;
}
 
開發者ID:yandex,項目名稱:opentsdb-flume,代碼行數:19,代碼來源:LegacyHttpSource.java

示例7: readInternal

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
protected Object[] readInternal(Class<?>[] parameterTypes, String payload) throws Exception {
	JsonFactory jsonFactory = this.objectMapper.getJsonFactory();
	JsonParser jp = jsonFactory.createJsonParser(payload);
	JsonToken token;
	List<Object> lObjs = new ArrayList<Object>();
	int i=0;
	while ((token = jp.nextToken()) != null) {
	    switch (token) {
	    	case VALUE_NUMBER_INT:
               case VALUE_STRING:
	        case START_OBJECT:
	        	Object obj = jp.readValueAs(parameterTypes[i]);
	        	lObjs.add(obj);
			    i++;
	            break;
		default:
			break;
	    }
	}
	if( lObjs.size() != parameterTypes.length) {
		throw new Exception("Parsed parameters do not match requested types.");
	}
	Object [] parametersFound = lObjs.toArray();
	return parametersFound;
}
 
開發者ID:Appverse,項目名稱:appverse-server,代碼行數:26,代碼來源:CustomMappingJacksonHttpMessageConverter.java

示例8: getSpecificJSONValue

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private String getSpecificJSONValue(HttpResponse response, String jsonKey) throws JsonParseException, IllegalStateException, IOException {
	InputStream content = response.getEntity().getContent();
	if (isSuccessfulResponse(response)) {
		JsonFactory f = new JsonFactory();
		JsonParser jp = f.createJsonParser(content);
		while ((jp.nextToken()) != JsonToken.END_OBJECT) {
			if (jsonKey.equals(jp.getCurrentName())) {
				jp.nextToken();
				return jp.getText();
			}
		}
	} else {
		String string = IOUtils.toString(content);
		System.err.println(string);
	}
	return null;
}
 
開發者ID:ExLibrisGroup,項目名稱:Rosetta.dps-sdk-projects,代碼行數:18,代碼來源:CDMIConnector.java

示例9: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public IPv6Net deserialize(JsonParser jp,
                           DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    IPv6Net ipv6Net = null;

    jp.nextToken();        // Move to JsonToken.START_OBJECT
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String fieldname = jp.getCurrentName();
        if ("value".equals(fieldname)) {
            String value = jp.getText();
            log.debug("Fieldname: {} Value: {}", fieldname, value);
            ipv6Net = new IPv6Net(value);
        }
    }
    return ipv6Net;
}
 
開發者ID:opennetworkinglab,項目名稱:spring-open,代碼行數:19,代碼來源:IPv6NetDeserializer.java

示例10: parseRoom

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
public static Room parseRoom(HipChat origin, InputStream input) throws JsonParseException, JsonMappingException, IOException
{
    JsonParser jp = HipChat.JSON_FACTORY.createJsonParser(input);
    ObjectMapper mapper = new ObjectMapper();
    Room room = null;

    jp.nextToken(); // START_OBJECT
    while (jp.nextToken() != JsonToken.END_OBJECT)
    {
        String tag = jp.getText();
        if ("room".equals(tag))
        {
            jp.nextToken(); // START_OBJECT
            room = parseRoom(origin, mapper, jp);
        }
    }

    return room;

}
 
開發者ID:blazsolar,項目名稱:gradle-hipchat-plugin,代碼行數:21,代碼來源:RoomParser.java

示例11: parseUser

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
public static User parseUser(HipChat origin, InputStream input) throws JsonParseException, JsonMappingException, IOException
{
    JsonParser jp = HipChat.JSON_FACTORY.createJsonParser(input);
    ObjectMapper mapper = new ObjectMapper();
    User user = null;

    jp.nextToken(); // START_OBJECT
    while (jp.nextToken() != JsonToken.END_OBJECT)
    {
        String tag = jp.getText();
        if ("user".equals(tag))
        {
            jp.nextToken(); // START_OBJECT
            user = parseUser(origin, mapper, jp);
        }
    }

    return user;
}
 
開發者ID:blazsolar,項目名稱:gradle-hipchat-plugin,代碼行數:20,代碼來源:UserParser.java

示例12: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
public int[] deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
  throws IOException, JsonProcessingException
{
  if (!paramJsonParser.isExpectedStartArrayToken())
    return handleNonArray(paramJsonParser, paramDeserializationContext);
  ArrayBuilders.IntBuilder localIntBuilder = paramDeserializationContext.getArrayBuilders().getIntBuilder();
  int[] arrayOfInt = (int[])localIntBuilder.resetAndStart();
  int k;
  for (int i = 0; paramJsonParser.nextToken() != JsonToken.END_ARRAY; i = k)
  {
    int j = _parseIntPrimitive(paramJsonParser, paramDeserializationContext);
    if (i >= arrayOfInt.length)
    {
      arrayOfInt = (int[])localIntBuilder.appendCompletedChunk(arrayOfInt, i);
      i = 0;
    }
    k = i + 1;
    arrayOfInt[i] = j;
  }
  return (int[])localIntBuilder.completeAndClearBuffer(arrayOfInt, i);
}
 
開發者ID:zhangjianying,項目名稱:12306-android-Decompile,代碼行數:22,代碼來源:ArrayDeserializers.java

示例13: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public List<Date> deserialize( final JsonParser parser, final DeserializationContext context )
  throws IOException
{
  if ( !parser.isExpectedStartArrayToken() )
  {
    throw context.mappingException( List.class );
  }
  final ArrayList<Date> result = new ArrayList<Date>();

  final DateFormat formatter = DateUtil.newDateFormatter();
  JsonToken token;
  while ( JsonToken.END_ARRAY != ( token = parser.nextToken() ) )
  {
    if ( JsonToken.VALUE_NULL == token )
    {
      throw context.mappingException( List.class );
    }
    result.add( DateUtil.parse( formatter, parser.getText() ) );
  }
  return result;
}
 
開發者ID:realityforge,項目名稱:gwt-datatypes,代碼行數:23,代碼來源:DateListDeserializer.java

示例14: getVaueAsTree

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private static List<JsonElement> getVaueAsTree(JsonParser in) throws IOException {
	int level = 0;
	List<JsonElement> result = new ArrayList<JsonElement>();
	do {
		JsonToken t = in.getCurrentToken();
		switch (t) {
			case START_OBJECT:
			case START_ARRAY:
				level++;
				result.add(new JsonElement(t));
				break;
			case END_OBJECT:
			case END_ARRAY:
				level--;
				result.add(new JsonElement(t));
				break;
			case FIELD_NAME:
			case VALUE_STRING:
			case VALUE_NUMBER_INT:
			case VALUE_NUMBER_FLOAT:
			case VALUE_TRUE:
			case VALUE_FALSE:
			case VALUE_NULL:
				result.add(new JsonElement(t, in.getText()));
				break;
		}
		in.nextToken();
	} while (level != 0);
	result.add(new JsonElement(null));
	return result;
}
 
開發者ID:Celos,項目名稱:avro-json-decoder,代碼行數:32,代碼來源:ExtendedJsonDecoder.java

示例15: injectDefaultValueIfAvailable

import org.codehaus.jackson.JsonParser; //導入方法依賴的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


注:本文中的org.codehaus.jackson.JsonParser.nextToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。