本文整理匯總了Java中org.codehaus.jackson.JsonParser.getCurrentToken方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.getCurrentToken方法的具體用法?Java JsonParser.getCurrentToken怎麽用?Java JsonParser.getCurrentToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.JsonParser
的用法示例。
在下文中一共展示了JsonParser.getCurrentToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: BackportedJacksonMappingIterator
import org.codehaus.jackson.JsonParser; //導入方法依賴的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();
}
}
}
示例2: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的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);
}
示例3: _parseDate
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
protected java.util.Date _parseDate(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
JsonToken localJsonToken = paramJsonParser.getCurrentToken();
try
{
if (localJsonToken == JsonToken.VALUE_NUMBER_INT)
return new java.util.Date(paramJsonParser.getLongValue());
if (localJsonToken == JsonToken.VALUE_STRING)
{
String str = paramJsonParser.getText().trim();
if (str.length() == 0)
return null;
return paramDeserializationContext.parseDate(str);
}
throw paramDeserializationContext.mappingException(this._valueClass);
}
catch (IllegalArgumentException localIllegalArgumentException)
{
}
throw paramDeserializationContext.weirdStringException(this._valueClass, "not a valid representation (error: " + localIllegalArgumentException.getMessage() + ")");
}
示例4: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public NodeRef deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
JsonToken curr = jp.getCurrentToken();
if (curr == JsonToken.VALUE_STRING)
{
String nodeRefString = jp.getText();
NodeRef nodeRef = getNodeRef(nodeRefString);
return nodeRef;
}
else
{
throw new IOException("Unable to deserialize nodeRef: " + curr.asString());
}
}
示例5: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的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);
}
示例6: handleNonArray
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private final Collection<Object> handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Collection<Object> paramCollection)
throws IOException, JsonProcessingException
{
if (!paramDeserializationContext.isEnabled(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY))
throw paramDeserializationContext.mappingException(this._collectionType.getRawClass());
JsonDeserializer localJsonDeserializer = this._valueDeserializer;
TypeDeserializer localTypeDeserializer = this._valueTypeDeserializer;
Object localObject;
if (paramJsonParser.getCurrentToken() == JsonToken.VALUE_NULL)
localObject = null;
while (true)
{
paramCollection.add(localObject);
return paramCollection;
if (localTypeDeserializer == null)
{
localObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
continue;
}
localObject = localJsonDeserializer.deserializeWithType(paramJsonParser, paramDeserializationContext, localTypeDeserializer);
}
}
示例7: deserializeObject
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
protected final ObjectNode deserializeObject(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
ObjectNode localObjectNode = paramDeserializationContext.getNodeFactory().objectNode();
JsonToken localJsonToken = paramJsonParser.getCurrentToken();
if (localJsonToken == JsonToken.START_OBJECT);
for (localJsonToken = paramJsonParser.nextToken(); localJsonToken == JsonToken.FIELD_NAME; localJsonToken = paramJsonParser.nextToken())
{
String str = paramJsonParser.getCurrentName();
paramJsonParser.nextToken();
JsonNode localJsonNode1 = deserializeAny(paramJsonParser, paramDeserializationContext);
JsonNode localJsonNode2 = localObjectNode.put(str, localJsonNode1);
if (localJsonNode2 == null)
continue;
_handleDuplicateField(str, localObjectNode, localJsonNode2, localJsonNode1);
}
return localObjectNode;
}
示例8: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
public Map<Object, Object> deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
JsonToken localJsonToken = paramJsonParser.getCurrentToken();
if ((localJsonToken != JsonToken.START_OBJECT) && (localJsonToken != JsonToken.FIELD_NAME) && (localJsonToken != JsonToken.END_OBJECT))
throw paramDeserializationContext.mappingException(getMapClass());
if (this._propertyBasedCreator != null)
return _deserializeUsingCreator(paramJsonParser, paramDeserializationContext);
if (this._defaultCtor == null)
throw paramDeserializationContext.instantiationException(getMapClass(), "No default constructor found");
try
{
Map localMap = (Map)this._defaultCtor.newInstance(new Object[0]);
_readAndBind(paramJsonParser, paramDeserializationContext, localMap);
return localMap;
}
catch (Exception localException)
{
}
throw paramDeserializationContext.instantiationException(getMapClass(), localException);
}
示例9: 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;
}
示例10: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public Duration deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws JsonParseException, IOException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Duration(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
return formatter.parsePeriod(str).toStandardDuration();
}
throw ctxt.mappingException(Duration.class);
}
示例11: jsonToHostDefinition
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
protected void jsonToHostDefinition(String json, HostDefinition host) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
else if (n.equals("attachment")) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String field = jp.getCurrentName();
if (field.equals("id")) {
host.attachment = jp.getText();
} else if (field.equals("mac")) {
host.mac = jp.getText();
}
}
}
}
jp.close();
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:39,代碼來源:HostResource.java
示例12: getEntryNameFromJson
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
/**
* Gets the entry name of a flow mod
* @param fmJson The OFFlowMod in a JSON representation
* @return The name of the OFFlowMod, null if not found
* @throws IOException If there was an error parsing the JSON
*/
public static String getEntryNameFromJson(String fmJson) throws IOException{
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n == "name")
return jp.getText();
}
return null;
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:38,代碼來源:StaticFlowEntries.java
示例13: jsonExtractSubnetMask
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
/**
* Extracts subnet mask from a JSON string
* @param fmJson The JSON formatted string
* @return The subnet mask
* @throws IOException If there was an error parsing the JSON
*/
public static String jsonExtractSubnetMask(String fmJson) throws IOException {
String subnet_mask = "";
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(fmJson);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n == "subnet-mask") {
subnet_mask = jp.getText();
break;
}
}
return subnet_mask;
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:41,代碼來源:FirewallResource.java
示例14: getVaueAsTree
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@SuppressWarnings("incomplete-switch")
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: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
public final Object deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
if (paramJsonParser.getCurrentToken() == JsonToken.VALUE_NULL)
{
if (this._nullProvider == null)
return null;
return this._nullProvider.nullValue(paramDeserializationContext);
}
if (this._valueTypeDeserializer != null)
return this._valueDeserializer.deserializeWithType(paramJsonParser, paramDeserializationContext, this._valueTypeDeserializer);
return this._valueDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
}