本文整理匯總了Java中com.fasterxml.jackson.core.JsonParser.getValueAsString方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.getValueAsString方法的具體用法?Java JsonParser.getValueAsString怎麽用?Java JsonParser.getValueAsString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.core.JsonParser
的用法示例。
在下文中一共展示了JsonParser.getValueAsString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override public AnInterface deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException {
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new AssertionError("Expected start object.");
}
String name = null;
while (jp.nextToken() != JsonToken.END_OBJECT) {
switch (jp.getCurrentName()) {
case "name":
name = jp.getValueAsString();
break;
}
}
return new AnImplementation(name);
}
示例2: readRecord
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
Map<String, Object> readRecord(JsonParser jp) throws IOException {
Map<String, Object> record = new HashMap<>();
String fielName = "";
Object value;
JsonToken token;
while((token = jp.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.FIELD_NAME) {
fielName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_STRING) {
value = jp.getValueAsString();
record.put(fielName, value);
} else if (token == JsonToken.VALUE_NUMBER_INT) {
value = jp.getValueAsLong();
record.put(fielName, value);
}
}
//System.out.println(record.toString());
return record;
}
示例3: getValueFromFieldType
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static Object getValueFromFieldType(JsonParser parser, MinorType fieldType) throws IOException {
switch (fieldType) {
case BIGINT:
return parser.getLongValue();
case VARCHAR:
return parser.getValueAsString();
case FLOAT4:
return parser.getFloatValue();
case BIT:
return parser.getBooleanValue();
case LATE:
case NULL:
return null;
default:
throw new RuntimeException("Unexpected Field type to return value: " + fieldType.toString());
}
}
示例4: deserializeWithRetry
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private Collection<Object> deserializeWithRetry(JsonParser p, DeserializationContext ctxt, JavaType contentType) throws IOException {
final CollectionType collectionType = ctxt.getTypeFactory().constructCollectionType(Collection.class, contentType);
try {
return p.getCodec().readValue(p, collectionType);
} catch (JsonMappingException e) {
// attempt to read the value as string
final String escapedString = p.getValueAsString();
// stop here if value could not be read
if (isNull(escapedString)) {
throw ctxt.instantiationException(Collection.class, "Read null value when attempting to deserialize " + collectionType.toString());
}
// un-escape double quotes
String unescapedString = escapedString.replaceAll("\"", "\"");
// and attempt to parse again
return new ObjectMapper().readValue(unescapedString, collectionType);
}
}
示例5: parseField
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
protected void parseField(String fieldName, JsonParser parser) throws IOException {
switch (fieldName) {
case "order_id":
parser.nextToken();
orderId = parser.getValueAsString();
break;
case "reason":
parser.nextToken();
reason = parser.getValueAsString();
break;
case "remaining_size":
parser.nextToken();
remainingSize = new BigDecimal(parser.getValueAsString());
break;
default:
break;
}
}
示例6: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static SubscribeMessage deserialize(JsonParser jp) throws IOException {
jp.nextToken();
long request = jp.getLongValue();
MatchPolicy match = MatchPolicy.EXACT;
jp.nextToken();
boolean getRetained = false;
Map<String, Object> options = ParserUtil.readObject(jp);
if (options != null) {
String extValue = (String) options.get("match");
if (extValue != null) {
match = MatchPolicy.fromExtValue(extValue);
if (match == null) {
match = MatchPolicy.EXACT;
}
}
getRetained = (boolean) options.getOrDefault("get_retained", false);
}
jp.nextToken();
String topic = jp.getValueAsString();
return new SubscribeMessage(request, topic, match, getRetained);
}
示例7: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static ErrorMessage deserialize(JsonParser jp) throws IOException {
jp.nextToken();
int type = jp.getIntValue();
jp.nextToken();
long request = jp.getLongValue();
jp.nextToken();
ParserUtil.readObject(jp);
jp.nextToken();
String error = jp.getValueAsString();
List<Object> arguments = null;
JsonToken token = jp.nextToken();
if (token == JsonToken.START_ARRAY) {
arguments = ParserUtil.readArray(jp);
}
Map<String, Object> argumentsKw = null;
token = jp.nextToken();
if (token == JsonToken.START_OBJECT) {
argumentsKw = ParserUtil.readObject(jp);
}
return new ErrorMessage(type, request, error, arguments, argumentsKw);
}
示例8: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public BigDecimal deserialize(final JsonParser parser, final DeserializationContext ctx) throws IOException {
final String val = parser.getValueAsString();
if ("N/A".equalsIgnoreCase(val)) {
return null;
}
return parser.getDecimalValue();
}
示例9: parseField
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public void parseField(MultipleFieldNamesModel instance, String fieldName, JsonParser jsonParser) throws IOException {
if ("possible_double_name_1".equals(fieldName) || "possible_double_name_2".equals(fieldName)) {
instance.testDouble = jsonParser.getValueAsDouble();
} else if ("possible_float_name_1".equals(fieldName) || "possible_float_name_2".equals(fieldName)){
instance.testFloat = (float)jsonParser.getValueAsDouble();
} else if ("possible_int_name_1".equals(fieldName) || "possible_int_name_2".equals(fieldName)){
instance.testInt = jsonParser.getValueAsInt();
} else if ("possible_long_name_1".equals(fieldName) || "possible_long_name_2".equals(fieldName)){
instance.testLong = jsonParser.getValueAsLong();
} else if ("possible_string_name_1".equals(fieldName) || "possible_string_name_2".equals(fieldName)){
instance.testString = jsonParser.getValueAsString(null);
}
}
示例10: parseField
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public void parseField(SimpleGenericModelWithExtends<T> instance, String fieldName, JsonParser jsonParser) throws IOException {
if ("date".equals(fieldName)) {
instance.date = getjava_util_Date_type_converter().parse(jsonParser);
} else if ("string".equals(fieldName)) {
instance.string = jsonParser.getValueAsString(null);
} else if ("test_double".equals(fieldName)) {
instance.testDouble = jsonParser.getValueAsDouble();
} else if ("test_double_obj".equals(fieldName)) {
instance.testDoubleObj = jsonParser.getCurrentToken() == JsonToken.VALUE_NULL ? null : Double.valueOf(jsonParser.getValueAsDouble());
} else if ("test_float".equals(fieldName)) {
instance.testFloat = (float)jsonParser.getValueAsDouble();
} else if ("test_float_obj".equals(fieldName)) {
instance.testFloatObj = jsonParser.getCurrentToken() == JsonToken.VALUE_NULL ? null : new Float(jsonParser.getValueAsDouble());
} else if ("test_int".equals(fieldName)) {
instance.testInt = jsonParser.getValueAsInt();
} else if ("test_int_obj".equals(fieldName)) {
instance.testIntObj = jsonParser.getCurrentToken() == JsonToken.VALUE_NULL ? null : Integer.valueOf(jsonParser.getValueAsInt());
} else if ("test_long".equals(fieldName)) {
instance.testLong = jsonParser.getValueAsLong();
} else if ("test_long_obj".equals(fieldName)) {
instance.testLongObj = jsonParser.getCurrentToken() == JsonToken.VALUE_NULL ? null : Long.valueOf(jsonParser.getValueAsLong());
} else if ("test_string".equals(fieldName)) {
instance.testString = jsonParser.getValueAsString(null);
} else if ("test_t".equals(fieldName)) {
instance.testT = m84ClassJsonMapper.parse(jsonParser);
}
}
示例11: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static CallMessage deserialize(JsonParser jp) throws IOException {
jp.nextToken();
long request = jp.getLongValue();
boolean discloseMe = false;
jp.nextToken();
Map<String, Object> options = ParserUtil.readObject(jp);
if (options != null) {
discloseMe = (boolean) options.getOrDefault("disclose_me", false);
}
jp.nextToken();
String procedure = jp.getValueAsString();
List<Object> arguments = null;
JsonToken token = jp.nextToken();
if (token == JsonToken.START_ARRAY) {
arguments = ParserUtil.readArray(jp);
}
Map<String, Object> argumentsKw = null;
token = jp.nextToken();
if (token == JsonToken.START_OBJECT) {
argumentsKw = ParserUtil.readObject(jp);
}
return new CallMessage(request, procedure, arguments, argumentsKw, discloseMe);
}
示例12: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Profile deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
if (isImageApiProfile(p.getValueAsString())) {
return new ImageApiProfile(p.getValueAsString());
} else {
return new Profile(URI.create(p.getValueAsString()));
}
} else if (p.getCurrentToken() == JsonToken.START_OBJECT) {
return p.getCodec().readValue(p, ImageApiProfile.class);
} else {
return (Profile) defaultDeserializer.deserialize(p, ctxt);
}
}
示例13: parseField
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
protected void parseField(String fieldName, JsonParser parser) throws IOException {
switch (fieldName) {
case "order_id":
parser.nextToken();
orderId = parser.getValueAsString();
break;
case "remaining_size":
parser.nextToken();
remainingSize = new BigDecimal(parser.getValueAsString());
break;
default:
break;
}
}
示例14: deserialize
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Type deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String enumStr = p.getValueAsString();
Type type = TYPES.get(enumStr.toLowerCase());
if(type != null){
return type;
}
logger.debug("Dremio is unable to consume the field type {}, hiding from schema.", enumStr);
return ElasticMappingSet.Type.UNKNOWN;
}
示例15: parseFieldName
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private static void parseFieldName(JsonParser jsonParser, JsonParsingContext parsingContext) throws IOException {
switch (jsonParser.getCurrentName()) {
case NodeGenericMetadataJsonSerializer.TYPE:
jsonParser.nextToken();
parsingContext.type = jsonParser.getValueAsString();
break;
case NodeGenericMetadataJsonSerializer.NAME:
jsonParser.nextToken();
parsingContext.name = jsonParser.getValueAsString();
break;
case NodeGenericMetadataJsonSerializer.VALUE:
Objects.requireNonNull(parsingContext.name);
Objects.requireNonNull(parsingContext.type);
jsonParser.nextToken();
switch (parsingContext.type) {
case NodeGenericMetadataJsonSerializer.STRING:
parsingContext.metadata.setString(parsingContext.name, jsonParser.getValueAsString());
break;
case NodeGenericMetadataJsonSerializer.DOUBLE:
parsingContext.metadata.setDouble(parsingContext.name, jsonParser.getValueAsDouble());
break;
case NodeGenericMetadataJsonSerializer.INT:
parsingContext.metadata.setInt(parsingContext.name, jsonParser.getValueAsInt());
break;
case NodeGenericMetadataJsonSerializer.BOOLEAN:
parsingContext.metadata.setBoolean(parsingContext.name, jsonParser.getValueAsBoolean());
break;
default:
throw new AssertionError("Unexpected metadata type " + parsingContext.type);
}
break;
default:
throw new AssertionError("Unexpected field: " + jsonParser.getCurrentName());
}
}