use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project elasticsearch by elastic.
the class ElasticsearchHostsSniffer method readHosts.
private List<HttpHost> readHosts(HttpEntity entity) throws IOException {
try (InputStream inputStream = entity.getContent()) {
JsonParser parser = jsonFactory.createParser(inputStream);
if (parser.nextToken() != JsonToken.START_OBJECT) {
throw new IOException("expected data to start with an object");
}
List<HttpHost> hosts = new ArrayList<>();
while (parser.nextToken() != JsonToken.END_OBJECT) {
if (parser.getCurrentToken() == JsonToken.START_OBJECT) {
if ("nodes".equals(parser.getCurrentName())) {
while (parser.nextToken() != JsonToken.END_OBJECT) {
JsonToken token = parser.nextToken();
assert token == JsonToken.START_OBJECT;
String nodeId = parser.getCurrentName();
HttpHost sniffedHost = readHost(nodeId, parser, this.scheme);
if (sniffedHost != null) {
logger.trace("adding node [" + nodeId + "]");
hosts.add(sniffedHost);
}
}
} else {
parser.skipChildren();
}
}
}
return hosts;
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project java-chassis by ServiceComb.
the class AbstractDeserializer method deserialize.
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
Object result = createResult();
for (String fieldName = p.nextFieldName(); fieldName != null; fieldName = p.nextFieldName()) {
// p实际是ProtobufParser,其内部是可以直接取到proto field的,理论上可以根据id来索引
// 可是field默认没暴露出来,所以,直接用name索引了
AbstractFieldCodec.ReaderHelpData helpData = readerHelpDataMap.get(fieldName);
if (helpData == null) {
continue;
}
JsonToken t = p.nextToken();
// Note: must handle null explicitly here; value deserializers won't
Object value = null;
if (t == JsonToken.VALUE_NULL) {
value = helpData.getDeser().getNullValue(ctxt);
} else {
value = helpData.getDeser().deserialize(p, ctxt);
}
result = updateResult(result, value, helpData);
}
return result;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project jackson-core by FasterXML.
the class TrailingCommasTest method assertEnd.
private void assertEnd(JsonParser p) throws IOException {
// Issue #325
if (!(p instanceof UTF8DataInputJsonParser)) {
JsonToken next = p.nextToken();
assertNull("expected end of stream but found " + next, next);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class JsonReader method write.
@Override
public ReadState write(ComplexWriter writer) throws IOException {
ReadState readState = null;
try {
JsonToken t = lastSeenJsonToken;
if (t == null || t == JsonToken.END_OBJECT) {
t = parser.nextToken();
}
while (!parser.hasCurrentToken() && !parser.isClosed()) {
t = parser.nextToken();
}
lastSeenJsonToken = null;
if (parser.isClosed()) {
return ReadState.END_OF_STREAM;
}
readState = writeToVector(writer, t);
switch(readState) {
case END_OF_STREAM:
break;
case WRITE_SUCCEED:
break;
default:
throw getExceptionWithContext(UserException.dataReadError(), currentFieldName, null).message("Failure while reading JSON. (Got an invalid read state %s )", readState.toString()).build(logger);
}
} catch (com.fasterxml.jackson.core.JsonParseException ex) {
if (ignoreJSONParseError()) {
if (processJSONException() == JsonExceptionProcessingState.END_OF_STREAM) {
return ReadState.JSON_RECORD_PARSE_EOF_ERROR;
} else {
return ReadState.JSON_RECORD_PARSE_ERROR;
}
} else {
throw ex;
}
}
return readState;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project alfresco-remote-api by Alfresco.
the class RestApiStringDeserializer method deserializeImpl.
private String deserializeImpl(JsonParser p, DeserializationContext ctxt) throws IOException {
if (p.hasToken(JsonToken.VALUE_STRING)) {
return p.getText();
}
JsonToken t = p.getCurrentToken();
// [databind#381]
if (t == JsonToken.START_ARRAY) {
return _deserializeFromArray(p, ctxt);
}
// need to gracefully handle byte[] data, as base64
if (t == JsonToken.VALUE_EMBEDDED_OBJECT) {
Object ob = p.getEmbeddedObject();
if (ob == null) {
return null;
}
if (ob instanceof byte[]) {
return ctxt.getBase64Variant().encode((byte[]) ob, false);
}
// otherwise, try conversion using toString()...
return ob.toString();
}
// allow coercions for other scalar types
String text = p.getValueAsString();
if (text != null) {
return text;
}
return (String) ctxt.handleUnexpectedToken(_valueClass, p);
}
Aggregations