use of org.codehaus.jackson.JsonToken in project neo4j by neo4j.
the class StatementDeserializer method beginsWithCorrectTokens.
private boolean beginsWithCorrectTokens() throws IOException {
List<JsonToken> expectedTokens = asList(START_OBJECT, FIELD_NAME, START_ARRAY);
String expectedField = "statements";
List<JsonToken> foundTokens = new ArrayList<>();
for (int i = 0; i < expectedTokens.size(); i++) {
JsonToken token = input.nextToken();
if (i == 0 && token == null) {
return false;
}
if (token == FIELD_NAME && !expectedField.equals(input.getText())) {
addError(new Neo4jError(Status.Request.InvalidFormat, new DeserializationException(String.format("Unable to deserialize request. " + "Expected first field to be '%s', but was '%s'.", expectedField, input.getText()))));
return false;
}
foundTokens.add(token);
}
if (!expectedTokens.equals(foundTokens)) {
addError(new Neo4jError(Status.Request.InvalidFormat, new DeserializationException(String.format("Unable to deserialize request. " + "Expected %s, found %s.", expectedTokens, foundTokens))));
return false;
}
return true;
}
use of org.codehaus.jackson.JsonToken in project neo4j by neo4j.
the class BatchOperations method parseAndPerform.
protected void parseAndPerform(UriInfo uriInfo, HttpHeaders httpHeaders, HttpServletRequest req, InputStream body, Map<Integer, String> locations) throws IOException, ServletException {
JsonParser jp = jsonFactory.createJsonParser(body);
JsonToken token;
RequestData requestData = RequestData.from(req);
while ((token = jp.nextToken()) != null) {
if (token == JsonToken.START_OBJECT) {
String jobMethod = "", jobPath = "", jobBody = "";
Integer jobId = null;
while ((token = jp.nextToken()) != JsonToken.END_OBJECT && token != null) {
String field = jp.getText();
jp.nextToken();
switch(field) {
case METHOD_KEY:
jobMethod = jp.getText().toUpperCase();
break;
case TO_KEY:
jobPath = jp.getText();
break;
case ID_KEY:
jobId = jp.getIntValue();
break;
case BODY_KEY:
jobBody = readBody(jp);
break;
default:
break;
}
}
// Read one job description. Execute it.
performRequest(uriInfo, jobMethod, jobPath, jobBody, jobId, httpHeaders, locations, requestData);
}
}
}
use of org.codehaus.jackson.JsonToken in project OpenRefine by OpenRefine.
the class Cell method loadStreaming.
public static Cell loadStreaming(JsonParser jp, Pool pool) throws Exception {
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NULL || t != JsonToken.START_OBJECT) {
return null;
}
Serializable value = null;
String type = null;
Recon recon = null;
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jp.getCurrentName();
jp.nextToken();
if ("r".equals(fieldName)) {
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
String reconID = jp.getText();
recon = pool.getRecon(reconID);
} else {
// legacy
recon = Recon.loadStreaming(jp, pool);
}
} else if ("e".equals(fieldName)) {
value = new EvalError(jp.getText());
} else if ("v".equals(fieldName)) {
JsonToken token = jp.getCurrentToken();
if (token == JsonToken.VALUE_STRING) {
value = jp.getText();
} else if (token == JsonToken.VALUE_NUMBER_INT) {
value = jp.getLongValue();
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
value = jp.getDoubleValue();
} else if (token == JsonToken.VALUE_TRUE) {
value = true;
} else if (token == JsonToken.VALUE_FALSE) {
value = false;
}
} else if ("t".equals(fieldName)) {
type = jp.getText();
}
}
if (value != null) {
if (type != null && "date".equals(type)) {
value = ParsingUtilities.stringToDate((String) value);
}
return new Cell(value, recon);
} else {
return null;
}
}
use of org.codehaus.jackson.JsonToken in project OpenRefine by OpenRefine.
the class Recon method loadStreaming.
public static Recon loadStreaming(JsonParser jp, Pool pool) throws Exception {
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NULL || t != JsonToken.START_OBJECT) {
return null;
}
Recon recon = null;
long id = -1;
long judgmentHistoryEntry = -1;
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jp.getCurrentName();
jp.nextToken();
if ("id".equals(fieldName)) {
id = jp.getLongValue();
} else if ("judgmentHistoryEntry".equals(fieldName)) {
judgmentHistoryEntry = jp.getLongValue();
if (recon != null) {
recon.judgmentHistoryEntry = judgmentHistoryEntry;
}
} else {
if (recon == null) {
recon = new Recon(id, judgmentHistoryEntry);
}
if ("j".equals(fieldName)) {
recon.judgment = stringToJudgment(jp.getText());
} else if ("m".equals(fieldName)) {
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
// legacy case
String candidateID = jp.getText();
recon.match = pool.getReconCandidate(candidateID);
} else {
recon.match = ReconCandidate.loadStreaming(jp);
}
} else if ("f".equals(fieldName)) {
if (jp.getCurrentToken() != JsonToken.START_ARRAY) {
return null;
}
int feature = 0;
while (jp.nextToken() != JsonToken.END_ARRAY) {
if (feature < recon.features.length) {
JsonToken token = jp.getCurrentToken();
if (token == JsonToken.VALUE_STRING) {
recon.features[feature++] = jp.getText();
} else if (token == JsonToken.VALUE_NUMBER_INT) {
recon.features[feature++] = jp.getLongValue();
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
recon.features[feature++] = jp.getDoubleValue();
} else if (token == JsonToken.VALUE_FALSE) {
recon.features[feature++] = false;
} else if (token == JsonToken.VALUE_TRUE) {
recon.features[feature++] = true;
}
}
}
} else if ("c".equals(fieldName)) {
if (jp.getCurrentToken() != JsonToken.START_ARRAY) {
return null;
}
while (jp.nextToken() != JsonToken.END_ARRAY) {
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
// legacy case
String candidateID = jp.getText();
recon.addCandidate(pool.getReconCandidate(candidateID));
} else {
recon.addCandidate(ReconCandidate.loadStreaming(jp));
}
}
} else if ("service".equals(fieldName)) {
recon.service = jp.getText();
} else if ("identifierSpace".equals(fieldName)) {
recon.identifierSpace = jp.getText();
if ("null".equals(recon.identifierSpace)) {
recon.identifierSpace = FREEBASE_IDENTIFIER_SPACE;
}
} else if ("schemaSpace".equals(fieldName)) {
recon.schemaSpace = jp.getText();
if ("null".equals(recon.schemaSpace)) {
recon.schemaSpace = FREEBASE_SCHEMA_SPACE;
}
} else if ("judgmentAction".equals(fieldName)) {
recon.judgmentAction = jp.getText();
} else if ("judgmentBatchSize".equals(fieldName)) {
recon.judgmentBatchSize = jp.getIntValue();
} else if ("matchRank".equals(fieldName)) {
recon.matchRank = jp.getIntValue();
}
}
}
return recon;
}
use of org.codehaus.jackson.JsonToken in project spring-security-oauth by spring-projects.
the class JacksonArrayOrStringDeserializer method deserialize.
@Override
public Set<String> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonToken token = jp.getCurrentToken();
if (token.isScalarValue()) {
String list = jp.getText();
list = list.replaceAll("\\s+", ",");
return new LinkedHashSet<String>(Arrays.asList(StringUtils.commaDelimitedListToStringArray(list)));
}
return jp.readValueAs(new TypeReference<Set<String>>() {
});
}
Aggregations