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


Java JsonParser.getText方法代碼示例

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


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

示例1: jsonExtractSubnetMask

import com.fasterxml.jackson.core.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.createParser(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:xuraylei,項目名稱:fresco_floodlight,代碼行數:41,代碼來源:FirewallSubnetMaskResource.java

示例2: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public String deserialize(final JsonParser parser, final DeserializationContext ctxt)
    throws IOException, JsonProcessingException {
    final boolean hasStringValue = parser.hasToken(JsonToken.VALUE_STRING);

    if (!hasStringValue) {
        return null;
    }

    final String text = parser.getText();

    final String trimmed = text.trim();

    if (trimmed.isEmpty()) {
        return null;
    }

    return trimmed;
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:20,代碼來源:StringTrimmingJsonDeserializer.java

示例3: deserialize

import com.fasterxml.jackson.core.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());
       }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:18,代碼來源:NodeRefDeserializer.java

示例4: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Date deserialize(JsonParser gen, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    String date = gen.getText();

    if (StringUtils.isEmpty(date)) {
        return null;
    }

    if (StringUtils.isNumeric(date)) {
        return new Date(Long.valueOf(date));
    }
    try {
        DateTime dt = fmt.parseDateTime(date);
        return dt.toDate();
    } catch (Exception e) {
        throw new IOException(e);
    }
}
 
開發者ID:linuer,項目名稱:nan,代碼行數:19,代碼來源:FDateJsonDeserializer.java

示例5: parseBool

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/** Parsers a bool value out of the input. */
static boolean parseBool(JsonParser parser) throws IOException {
  JsonToken token = parser.currentToken();
  if (token.isBoolean()) {
    return parser.getBooleanValue();
  }
  String json = parser.getText();
  if (json.equals("true")) {
    return true;
  } else if (json.equals("false")) {
    return false;
  }
  throw new InvalidProtocolBufferException("Invalid bool value: " + json);
}
 
開發者ID:curioswitch,項目名稱:curiostack,代碼行數:15,代碼來源:ParseSupport.java

示例6: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Boolean deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
	if (parser != null && parser.getText() != null){
		return parser.getText().equals(ConstanteUtils.TYP_BOOLEAN_YES)?true:false;
	}
    return false;
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:8,代碼來源:SiScolRestUtils.java

示例7: getNextTextValue

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static String getNextTextValue(String fieldName, JsonParser parser) throws JsonParseException, IOException {
    JsonToken current = parser.nextToken(); // move to filed
    if (current != JsonToken.FIELD_NAME || !fieldName.equals(parser.getCurrentName())) {
        reportParseError("Error occoured while getting value by field name:" + fieldName, parser.getCurrentLocation());
    }
    current = parser.nextToken(); // move to value
    return parser.getText();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:JacksonGroupParser.java

示例8: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Date deserialize(JsonParser jsonParser,
                        DeserializationContext dc) throws JsonProcessingException {
    Date date = null;
    try {
        DateFormat dateFormat = new SimpleDateFormat(pattern);
        String val = jsonParser.getText();
        date = dateFormat.parse(val);
    } catch (ParseException | IOException pex) {
        throw new RuntimeException("json轉換Date異常,格式:" + pattern);
    }
    return date;
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:14,代碼來源:DateConvertDeserializer.java

示例9: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public OrderSide deserialize(JsonParser jp, DeserializationContext dc) throws IOException {
    final String jsonValue = jp.getText();
    for (final OrderSide enumValue : OrderSide.values()) {
        if (enumValue.getCode().equals(jsonValue)) {
            return enumValue;
        }
    }
    return null;
}
 
開發者ID:bitbankinc,項目名稱:java-bitbankcc,代碼行數:11,代碼來源:OrderSideDeserializer.java

示例10: parseMap

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/**
 * Parse a map of objects from a JsonParser.
 *
 * @param jsonParser The JsonParser, preconfigured to be at the START_ARRAY token.
 */
public Map<String, T> parseMap(JsonParser jsonParser) throws IOException {
    HashMap<String, T> map = new HashMap<String, T>();
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String key = jsonParser.getText();
        jsonParser.nextToken();
        if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
            map.put(key, null);
        } else{
            map.put(key, parse(jsonParser));
        }
    }
    return map;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:JsonMapper.java

示例11: parsePerson

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public void parsePerson(JsonParser parser) throws IOException {
    while (parser.nextToken() != JsonToken.END_ARRAY) {
        String token = parser.getCurrentName();
        if ("firstname".equals(token)) {
            parser.nextToken();
            String fname = parser.getText();
            out.println("firstname : " + fname);
        }
        if ("lastname".equals(token)) {
            parser.nextToken();
            String lname = parser.getText();
            out.println("lastname : " + lname);
        }
        if ("phone".equals(token)) {
            parser.nextToken();
            long phone = parser.getLongValue();
            out.println("phone : " + phone);
        }
        if ("address".equals(token)) {
            out.println("address :");
            parser.nextToken();
            while (parser.nextToken() != JsonToken.END_ARRAY) {
                out.println(parser.getText());
            }
        }
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-for-Data-Science,代碼行數:28,代碼來源:JSONExamples.java

示例12: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public OrderType deserialize(JsonParser jp, DeserializationContext dc) throws IOException {
    final String jsonValue = jp.getText();
    for (final OrderType enumValue : OrderType.values()) {
        if (enumValue.getCode().equals(jsonValue)) {
            return enumValue;
        }
    }
    return null;
}
 
開發者ID:bitbankinc,項目名稱:java-bitbankcc,代碼行數:11,代碼來源:OrderTypeDeserializer.java

示例13: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Enum deserialize(JsonParser parser, DeserializationContext ctx) throws IOException {
    String text = parser.getText();
    return Enums.getEnum(enumCls, prop, text).orElseGet(() ->
                                                                Stream.of(enumCls.getEnumConstants())
                                                                        .filter(e -> e.name().equals(text))
                                                                        .findFirst().orElse(null)
    );
}
 
開發者ID:thlcly,項目名稱:Dude,代碼行數:10,代碼來源:CustomEnumDeserializer.java

示例14: loadPart

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private static Part loadPart(int index, JsonParser parser, double location) throws IOException {
    if (parser.nextToken() != JsonToken.FIELD_NAME) {
        throw new IOException( "Field name expected.");
    }
    if (!Objects.equals(parser.getCurrentName(), "length")) {
        throw new IOException("length field expected.");
    }

    parser.nextToken();
    double length = parser.getDoubleValue();

    if (parser.nextToken() != JsonToken.FIELD_NAME) {
        throw new IOException("Field name expected.");
    }
    if (!Objects.equals(parser.getCurrentName(), "type")) {
        throw new IOException("type field expected.");
    }

    parser.nextToken();
    String val = parser.getText();
    Part.TYPE type;
    if (Objects.equals(val, "s")) {
        type = Part.TYPE.STRAIGHT;
    } else if (Objects.equals(val, "c")) {
        type = Part.TYPE.CURVED;
    } else {
        throw new IOException("Invalid part type detected.");
    }
    if (parser.nextToken() != JsonToken.END_OBJECT) {
        throw new IOException("Expected object to end.");
    }

    return new Part(index, type, length, location);
}
 
開發者ID:pushtechnology,項目名稱:racing-demo,代碼行數:35,代碼來源:RaceTrack.java

示例15: getEntryNameFromJson

import com.fasterxml.jackson.core.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.createParser(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 == StaticFlowEntryPusher.COLUMN_NAME)
			return jp.getText();
	}
	return null;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:37,代碼來源:StaticFlowEntries.java


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