本文整理汇总了Java中com.fasterxml.jackson.core.JsonToken.VALUE_STRING属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.VALUE_STRING属性的具体用法?Java JsonToken.VALUE_STRING怎么用?Java JsonToken.VALUE_STRING使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.fasterxml.jackson.core.JsonToken
的用法示例。
在下文中一共展示了JsonToken.VALUE_STRING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMissingInstantiator
@Override
public Object handleMissingInstantiator(DeserializationContext ctxt, Class<?> instClass, ValueInstantiator valueInsta,
JsonParser p, String msg) throws IOException {
/* FIXME: For some reason Jackson can't find the {@link Canvas(String)} constructor, so we do it ourselves:
* 1. Check if the deserializer bails out on a JSON string
* 2. Find a String-constructor on the target class
* 3. Build the object */
if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
}
try {
// Special case for empty strings in collection fields.
if (p.getValueAsString().isEmpty() && Collection.class.isAssignableFrom(instClass)) {
return instClass.getConstructor().newInstance();
} else {
Constructor<?> constructor = instClass.getConstructor(String.class);
return constructor.newInstance(p.getValueAsString());
}
} catch (Exception e) {
// Fall through
}
return super.handleMissingInstantiator(ctxt, instClass, valueInsta, p, msg);
}
示例2: objectText
@Override
public Object objectText() throws IOException {
JsonToken currentToken = parser.getCurrentToken();
if (currentToken == JsonToken.VALUE_STRING) {
return text();
} else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
return parser.getNumberValue();
} else if (currentToken == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
} else if (currentToken == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
} else if (currentToken == JsonToken.VALUE_NULL) {
return null;
} else {
return text();
}
}
示例3: objectBytes
@Override
public Object objectBytes() throws IOException {
JsonToken currentToken = parser.getCurrentToken();
if (currentToken == JsonToken.VALUE_STRING) {
return utf8Bytes();
} else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
return parser.getNumberValue();
} else if (currentToken == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
} else if (currentToken == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
} else if (currentToken == JsonToken.VALUE_NULL) {
return null;
} else {
//TODO should this really do UTF-8 conversion?
return utf8Bytes();
}
}
示例4: deserialize
@Override
public Foo deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING) {
String trim = p.getText().trim();
String[] split = trim.split(",");
Foo foo = new Foo();
foo.setName(split[0].split("=")[1]);
foo.setAge(Integer.parseInt(split[1].split("=")[1]));
return foo;
}
return (Foo) ctxt.handleUnexpectedToken(handledType(), p);
}
示例5: readRecord
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;
}
示例6: jsonToColumnValue
@Override
public Value jsonToColumnValue(JsonParser parser, ValueMetadata metadata) throws IOException {
JsonToken token;
Value value;
// Go to the next token
token = parser.nextToken();
if (token != JsonToken.VALUE_STRING && token != JsonToken.VALUE_NULL) {
throw new IOException("Unable to parse field " + metadata.getName() + " expected string or null at line " + parser.getCurrentLocation().getLineNr());
}
// Can be a integer or null
if (token == JsonToken.VALUE_STRING) {
value = new Value(parser.getValueAsString(), metadata);
} else {
// null
if (metadata.isNotNull()) {
throw new IOException("Unable to parse field " + metadata.getName() + " expected string but found null at line " + parser.getCurrentLocation().getLineNr());
}
value = new Value(metadata);
}
return value;
}
示例7: acceptString
private String acceptString() throws Exception {
if (parser.getCurrentToken() == JsonToken.VALUE_STRING) {
String stringValue = parser.getText();
parser.nextToken();
return stringValue;
} else {
throw new JSONException("syntax error, expect string, actual " + parser.getCurrentToken());
}
}
示例8: deserialize
@Override
public Service deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
ObjectMapper mapper = (ObjectMapper) p.getCodec();
if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
return new GenericService(null, p.getValueAsString());
}
ObjectNode obj = mapper.readTree(p);
if (isV1ImageService(obj)) {
return parseV1Service(obj);
} else if (isImageService(obj)) {
return mapper.treeToValue(obj, ImageService.class);
}
String context = null;
if (obj.has("@context")) {
context = obj.get("@context").asText();
}
JsonNode profileNode = obj.get("profile");
String profile = null;
if (profileNode != null) {
profile = profileNode.asText();
}
if (Objects.equals(context, ContentSearchService.CONTEXT)) {
if (Objects.equals(profile, AutocompleteService.PROFILE)) {
return mapper.treeToValue(obj, AutocompleteService.class);
} else {
return mapper.treeToValue(obj, ContentSearchService.class);
}
} else if (Objects.equals(context, AccessCookieService.CONTEXT)) {
return mapper.treeToValue(obj, AccessCookieService.class);
} else if (Objects.equals(context, GeoService.CONTEXT)) {
return mapper.treeToValue(obj, GeoService.class);
} else if (Objects.equals(context, PhysicalDimensionsService.CONTEXT)) {
return mapper.treeToValue(obj, PhysicalDimensionsService.class);
} else {
return mapper.treeToValue(obj, GenericService.class);
}
}
示例9: deserialize
@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);
}
}
示例10: deserialize
@Override
public SimpleI18NString deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
JsonProcessingException
{
JsonToken currentToken = jp.getCurrentToken();
if( currentToken != JsonToken.VALUE_STRING )
{
throw new JsonParseException("Must be a string", jp.getCurrentLocation());
}
String text = jp.getText();
return new SimpleI18NString(text);
}
示例11: getToken
private JsonToken getToken(final ValueType type, final VPackSlice value) {
final JsonToken token;
switch (type) {
case OBJECT:
token = JsonToken.START_OBJECT;
break;
case ARRAY:
token = JsonToken.START_ARRAY;
break;
case STRING:
token = JsonToken.VALUE_STRING;
break;
case BOOL:
token = value.isTrue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
break;
case DOUBLE:
token = JsonToken.VALUE_NUMBER_FLOAT;
break;
case INT:
case SMALLINT:
case UINT:
token = JsonToken.VALUE_NUMBER_INT;
break;
case NULL:
token = JsonToken.VALUE_NULL;
break;
default:
token = null;
break;
}
return token;
}
示例12: getValueAsString
@Override
public String getValueAsString(String defaultValue) throws IOException {
// The documentation is ambiguous about whether field names should
// return their text or the default value. To conform with the
// CBORParser, they will get the default value here.
if (currentToken != JsonToken.VALUE_STRING) {
if (currentToken == null || currentToken == JsonToken.VALUE_NULL || !currentToken.isScalarValue()) {
return defaultValue;
}
}
return getText();
}
示例13: getJsonToken
private JsonToken getJsonToken() {
if (reader.isNullValue()) {
return JsonToken.VALUE_NULL;
}
IonType currentType = reader.getType();
switch (currentType) {
case BLOB:
case CLOB:
return JsonToken.VALUE_EMBEDDED_OBJECT;
case BOOL:
return reader.booleanValue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
case DECIMAL:
return JsonToken.VALUE_NUMBER_FLOAT;
case FLOAT:
return JsonToken.VALUE_NUMBER_FLOAT;
case INT:
return JsonToken.VALUE_NUMBER_INT;
case LIST:
return JsonToken.START_ARRAY;
case SEXP:
return JsonToken.START_ARRAY;
case STRING:
return JsonToken.VALUE_STRING;
case STRUCT:
return JsonToken.START_OBJECT;
case SYMBOL:
return JsonToken.VALUE_STRING;
case TIMESTAMP:
return JsonToken.VALUE_EMBEDDED_OBJECT;
default:
throw new SdkClientException(String.format("Unhandled Ion type %s", currentType));
}
}
示例14: write
private void write(BitWriter writer, JsonToken token, JsonParser parser) throws IOException {
// TODO JASON - finish other cases
if (token == JsonToken.VALUE_NUMBER_INT) {
writer.writeBit(parser.getIntValue() == 1 ? 1 : 0);
} else if (token == JsonToken.VALUE_TRUE || token == JsonToken.VALUE_FALSE){
writer.writeBit(parser.getBooleanValue() ? 1 : 0);
} else if (token == JsonToken.VALUE_STRING) {
writer.writeBit(ElasticsearchJsonReader.parseElasticBoolean(parser.getValueAsString()) ? 1 : 0);
} else {
throw UserException.dataReadError()
.message("While reading from elasticsearch, unexpected data type in a boolean column: " + token).build(logger);
}
}
示例15: deserialize
@Override
public UUID deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
JsonToken token = parser.getCurrentToken();
if (token == JsonToken.VALUE_STRING) {
String string = parser.getValueAsString().trim();
return Url62.decode(string);
}
throw new IllegalStateException("This is not friendly id");
}