本文整理汇总了Java中org.codehaus.jackson.JsonToken类的典型用法代码示例。如果您正苦于以下问题:Java JsonToken类的具体用法?Java JsonToken怎么用?Java JsonToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonToken类属于org.codehaus.jackson包,在下文中一共展示了JsonToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readString
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
@Override
public String readString() throws IOException {
advance(Symbol.STRING);
if (parser.topSymbol() == Symbol.MAP_KEY_MARKER) {
parser.advance(Symbol.MAP_KEY_MARKER);
if (in.getCurrentToken() != JsonToken.FIELD_NAME) {
throw error("map-key");
}
} else {
if (in.getCurrentToken() != JsonToken.VALUE_STRING) {
throw error("string");
}
}
String result = in.getText();
in.nextToken();
return result;
}
示例2: readEnum
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
@Override
public int readEnum() throws IOException {
advance(Symbol.ENUM);
Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
in.getText();
int n = top.findLabel(in.getText());
if (n >= 0) {
in.nextToken();
return n;
}
throw new AvroTypeException("Unknown symbol in enum " + in.getText());
} else {
throw error("fixed");
}
}
示例3: readIndex
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
@Override
public int readIndex() throws IOException {
advance(Symbol.UNION);
Symbol.Alternative a = (Symbol.Alternative) parser.popSymbol();
String label;
if (in.getCurrentToken() == JsonToken.VALUE_NULL) {
label = "null";
} else if (in.getCurrentToken() == JsonToken.START_OBJECT &&
in.nextToken() == JsonToken.FIELD_NAME) {
label = in.getText();
in.nextToken();
parser.pushSymbol(Symbol.UNION_END);
} else {
throw error("start-union");
}
int n = a.findLabel(label);
if (n < 0)
throw new AvroTypeException("Unknown union branch " + label);
parser.pushSymbol(a.getSymbol(n));
return n;
}
示例4: readJsonEntry
import org.codehaus.jackson.JsonToken; //导入依赖的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;
}
示例5: getRequestBody
import org.codehaus.jackson.JsonToken; //导入依赖的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;
}
示例6: parse
import org.codehaus.jackson.JsonToken; //导入依赖的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()});
}
}
}
示例7: parseMetricArray
import org.codehaus.jackson.JsonToken; //导入依赖的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;
}
示例8: BackportedJacksonMappingIterator
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected BackportedJacksonMappingIterator(JavaType type, JsonParser jp, DeserializationContext ctxt, JsonDeserializer<?> deser) {
_type = type;
_parser = jp;
_context = ctxt;
_deserializer = (JsonDeserializer<T>) deser;
/* One more thing: if we are at START_ARRAY (but NOT root-level
* one!), advance to next token (to allow matching END_ARRAY)
*/
if (jp != null && jp.getCurrentToken() == JsonToken.START_ARRAY) {
JsonStreamContext sc = jp.getParsingContext();
// safest way to skip current token is to clear it (so we'll advance soon)
if (!sc.inRoot()) {
jp.clearCurrentToken();
}
}
}
示例9: hasNextValue
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
/**
* Equivalent of {@link #next} but one that may throw checked
* exceptions from Jackson due to invalid input.
*/
public boolean hasNextValue() throws IOException {
if (_parser == null) {
return false;
}
JsonToken t = _parser.getCurrentToken();
if (t == null) { // un-initialized or cleared; find next
t = _parser.nextToken();
// If EOF, no more
if (t == null) {
_parser.close();
return false;
}
// And similarly if we hit END_ARRAY; except that we won't close parser
if (t == JsonToken.END_ARRAY) {
return false;
}
}
return true;
}
示例10: deserialize
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
@Override
public Instant deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Instant(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser();
final DateTime dateTime = formatter.parseDateTime(str);
return new Instant(dateTime.getMillis());
}
throw ctxt.mappingException(Instant.class);
}
示例11: readGrants
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
/**
* Reads the list of grants from the JSON stream
* @param coronaSerializer The CoronaSerializer instance being used to read
* the JSON from disk
* @throws IOException
*/
private void readGrants(CoronaSerializer coronaSerializer)
throws IOException {
// Expecting the START_OBJECT token for grants
coronaSerializer.readStartObjectToken("grants");
JsonToken current = coronaSerializer.nextToken();
while (current != JsonToken.END_OBJECT) {
// We can access the key for the grant, but it is not required
// Expecting the START_OBJECT token for the grant
coronaSerializer.readStartObjectToken("grant");
coronaSerializer.readField("grantId");
GrantId grantId = new GrantId(coronaSerializer);
coronaSerializer.readField("grant");
ResourceRequestInfo resourceRequestInfo =
new ResourceRequestInfo(coronaSerializer);
// Expecting the END_OBJECT token for the grant
coronaSerializer.readEndObjectToken("grant");
// This will update the grants map and the resourceTypeToStatsMap map
addGrant(grantId.getSessionId(), resourceRequestInfo);
current = coronaSerializer.nextToken();
}
}
示例12: readSessions
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
/**
* Reads back the sessions map from a JSON stream
*
* @param coronaSerializer The CoronaSerializer instance to be used to
* read the JSON
* @throws IOException
*/
private void readSessions(CoronaSerializer coronaSerializer)
throws IOException {
coronaSerializer.readField("sessions");
// Expecting the START_OBJECT token for sessions
coronaSerializer.readStartObjectToken("sessions");
JsonToken current = coronaSerializer.nextToken();
while (current != JsonToken.END_OBJECT) {
String sessionId = coronaSerializer.getFieldName();
Session session = new Session(clusterManager.conf.getCMHeartbeatDelayMax(),
coronaSerializer);
sessions.put(sessionId, session);
current = coronaSerializer.nextToken();
}
// Done with reading the END_OBJECT token for sessions
}
示例13: readIdToGrant
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
/**
* Reads the idToGrant map from a JSON stream
*
* @param coronaSerializer The CoronaSerializer instance to be used to
* read the JSON
* @throws IOException
*/
private void readIdToGrant(CoronaSerializer coronaSerializer)
throws IOException {
coronaSerializer.readField("idToGrant");
// Expecting the START_OBJECT token for idToGrant
coronaSerializer.readStartObjectToken("idToGrant");
JsonToken current = coronaSerializer.nextToken();
while (current != JsonToken.END_OBJECT) {
Integer id = Integer.parseInt(coronaSerializer.getFieldName());
ResourceGrant resourceGrant =
coronaSerializer.readValueAs(ResourceGrant.class);
idToGrant.put(id, new ResourceGrant(resourceGrant));
current = coronaSerializer.nextToken();
}
// Done with reading the END_OBJECT token for idToGrant
}
示例14: readTypeToFirstWait
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
/**
* Reads the typeToFirstWait map from the JSON stream
*
* @param coronaSerializer The CoronaSerializer instance to be used to
* read the JSON
* @throws IOException
*/
private void readTypeToFirstWait(CoronaSerializer coronaSerializer)
throws IOException {
coronaSerializer.readField("typeToFirstWait");
// Expecting the START_OBJECT token for typeToFirstWait
coronaSerializer.readStartObjectToken("typeToFirstWait");
JsonToken current = coronaSerializer.nextToken();
while (current != JsonToken.END_OBJECT) {
String resourceTypeStr = coronaSerializer.getFieldName();
Long wait = coronaSerializer.readValueAs(Long.class);
current = coronaSerializer.nextToken();
if (wait == -1) {
wait = null;
}
typeToFirstWait.put(ResourceType.valueOf(resourceTypeStr), wait);
}
// Done with reading the END_OBJECT token for typeToFirstWait
}
示例15: readNameToNode
import org.codehaus.jackson.JsonToken; //导入依赖的package包/类
/**
* Reads the nameToNode map from the JSON stream
* @param coronaSerializer The CoronaSerializer instance to be used to
* read the JSON
* @throws IOException
*/
private void readNameToNode(CoronaSerializer coronaSerializer)
throws IOException {
coronaSerializer.readField("nameToNode");
// Expecting the START_OBJECT token for nameToNode
coronaSerializer.readStartObjectToken("nameToNode");
JsonToken current = coronaSerializer.nextToken();
while (current != JsonToken.END_OBJECT) {
// nodeName is the key, and the ClusterNode is the value here
String nodeName = coronaSerializer.getFieldName();
ClusterNode clusterNode = new ClusterNode(coronaSerializer);
if (!nameToNode.containsKey(nodeName)) {
nameToNode.put(nodeName, clusterNode);
}
current = coronaSerializer.nextToken();
}
// Done with reading the END_OBJECT token for nameToNode
}