本文整理匯總了Java中com.fasterxml.jackson.core.JsonToken.id方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonToken.id方法的具體用法?Java JsonToken.id怎麽用?Java JsonToken.id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.core.JsonToken
的用法示例。
在下文中一共展示了JsonToken.id方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processToken
import com.fasterxml.jackson.core.JsonToken; //導入方法依賴的package包/類
private JsonToken processToken(JsonToken curToken, JsonParser parser, JsonGenerator jgen)
throws IOException {
if (curToken.isStructEnd()) {
// this is our escape and base case.
return curToken;
}
if (curToken.isStructStart()) {
processStructStart(curToken, jgen);
JsonToken token = processToken(parser.nextToken(), parser, jgen);
while (!token.isStructEnd()) {
token = processToken(token, parser, jgen);
}
processStructEnd(token, jgen);
return parser.nextToken();
}
if (curToken.id() == JsonTokenId.ID_FIELD_NAME) {
String currentName = parser.getCurrentName();
if (isFiltered && filters.containsKey(parser.getCurrentName())) {
jgen.writeFieldName(currentName);
// perform filtering.
return filters.get(parser.getCurrentName()).processToken(parser.nextToken(), parser, jgen);
} else if (!isFiltered) {
jgen.writeFieldName(currentName);
return processToken(parser.nextToken(), parser, jgen);
} else {
parser.nextToken();
parser.skipChildren();
return processToken(parser.nextToken(), parser, jgen);
}
} else if (curToken.isScalarValue()) {
processValue(curToken, parser, jgen);
return parser.nextToken();
} else {
LOGGER.error(
"Unable to process the token {} with name {}.", curToken, parser.getCurrentName());
throw new RuntimeException(
"Unable to process the token " + curToken + " with name" + parser.getCurrentName());
}
}
示例2: processValue
import com.fasterxml.jackson.core.JsonToken; //導入方法依賴的package包/類
/**
* Uses a JsonToken + JsonParser to determine how to write a value to the JsonGenerator.
*
* <p>This separation exists so we can separate the iteration logic from the parsing logic.
*
* @param valueToken current token we are interested in from the parser
* @param parser current parser
* @param jgen JsonGenerator that is used for writing json onto an underlying stream
* @throws JsonGenerationException if access to the JsonParser throws a JsonGenerationException
* @throws IOException if the Jackson utilties (JsonParser or JsonGenerator) throw an IOException
*/
private void processValue(JsonToken valueToken, JsonParser parser, JsonGenerator jgen)
throws IOException {
if (valueToken.isBoolean()) {
jgen.writeBoolean(parser.getBooleanValue());
} else if (valueToken.isNumeric()) {
if (parser.getNumberType() == JsonParser.NumberType.INT) {
jgen.writeNumber(parser.getIntValue());
} else if (parser.getNumberType() == JsonParser.NumberType.DOUBLE) {
jgen.writeNumber(parser.getDoubleValue());
} else if (parser.getNumberType() == JsonParser.NumberType.FLOAT) {
jgen.writeNumber(parser.getFloatValue());
} else if (parser.getNumberType() == JsonParser.NumberType.LONG) {
jgen.writeNumber(parser.getLongValue());
} else if (parser.getNumberType() == JsonParser.NumberType.BIG_DECIMAL) {
jgen.writeNumber(parser.getDecimalValue());
} else if (parser.getNumberType() == JsonParser.NumberType.BIG_INTEGER) {
jgen.writeNumber(parser.getBigIntegerValue());
} else {
LOGGER.error("Found unsupported numeric value with name {}.", parser.getCurrentName());
throw new RuntimeException(
"Found unsupported numeric value with name " + parser.getCurrentName());
}
} else if (valueToken.id() == JsonTokenId.ID_STRING) {
jgen.writeString(parser.getText());
} else {
// Something bad just happened. Probably an unsupported type.
LOGGER.error(
"Found unsupported value type {} for name {}.", valueToken.id(), parser.getCurrentName());
throw new RuntimeException(
"Found unsupported value type " + valueToken.id() + " for name " + parser
.getCurrentName());
}
}
示例3: processStructStart
import com.fasterxml.jackson.core.JsonToken; //導入方法依賴的package包/類
private void processStructStart(JsonToken token, JsonGenerator jgen) throws IOException {
if (token.id() == JsonToken.START_OBJECT.id()) {
jgen.writeStartObject();
} else if (token.id() == JsonToken.START_ARRAY.id()) {
jgen.writeStartArray();
} else {
LOGGER.error("Illegal struct start {}", token.id());
throw new RuntimeException("Illegal struct start " + token.id());
}
}
示例4: processStructEnd
import com.fasterxml.jackson.core.JsonToken; //導入方法依賴的package包/類
private void processStructEnd(JsonToken token, JsonGenerator jgen)
throws IOException {
if (token.id() == JsonTokenId.ID_END_OBJECT) {
jgen.writeEndObject();
} else if (token.id() == JsonTokenId.ID_END_ARRAY) {
jgen.writeEndArray();
} else {
LOGGER.error("Illegal struct end {}", token.id());
throw new RuntimeException("Illegal struct end " + token.id());
}
}