本文整理匯總了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;
}
示例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;
}
示例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());
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
}
}
示例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;
}
示例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)
);
}
示例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);
}
示例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;
}