本文整理汇总了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;
}
示例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;
}
示例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());
}
示例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が返却されない");
}
示例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()});
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}