use of com.fasterxml.jackson.core.JsonToken in project moco by dreamhead.
the class CookieContainerDeserializer method deserialize.
@Override
public CookieContainer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
JsonToken currentToken = jp.getCurrentToken();
if (currentToken == JsonToken.VALUE_STRING) {
return CookieContainer.newContainer(jp.getText());
}
if (currentToken == JsonToken.START_OBJECT) {
jp.nextToken();
InternalCookieContainer container = get(jp.readValuesAs(InternalCookieContainer.class), 0);
return container.toContainer();
}
return (CookieContainer) ctxt.handleUnexpectedToken(CookieContainer.class, jp);
}
use of com.fasterxml.jackson.core.JsonToken in project moco by dreamhead.
the class FileContainerDeserializer method deserialize.
@Override
public FileContainer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
JsonToken currentToken = jp.getCurrentToken();
if (currentToken == JsonToken.VALUE_STRING) {
return asFileContainer(helper.text(jp));
}
if (currentToken == JsonToken.START_OBJECT) {
jp.nextToken();
String target = jp.getText().trim();
if (isForFileContainer(target)) {
return toFileContainer(jp);
}
return asFileContainer(helper.textContainer(jp, ctxt));
}
return (FileContainer) ctxt.handleUnexpectedToken(FileContainer.class, jp);
}
use of 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 com.fasterxml.jackson.core.JsonToken in project fastjson by alibaba.
the class JacksonGroupParser method parseDepartment.
private Department parseDepartment() throws Exception {
accept(JsonToken.START_OBJECT);
Department company = new Department();
for (; ; ) {
JsonToken tok = parser.getCurrentToken();
if (tok == JsonToken.END_OBJECT) {
break;
}
if (tok == JsonToken.FIELD_NAME) {
String name = parser.getCurrentName();
tok = parser.nextToken();
if ("name" == name) {
company.setName(acceptString(tok));
} else if ("description" == name) {
company.setDescription(acceptString(tok));
} else if ("id" == name) {
company.setId(acceptLong(tok));
} else if ("children" == name) {
parseDepartment(company.getChildren());
} else if ("members" == name) {
parseEmployee(company.getMembers());
} else {
throw new RuntimeException("not match property : " + name);
}
}
}
accept(JsonToken.END_OBJECT);
return company;
}
use of com.fasterxml.jackson.core.JsonToken in project fastjson by alibaba.
the class JacksonGroupParser method parseCompany.
private Company parseCompany() throws Exception {
Company company = new Company();
accept(JsonToken.START_OBJECT);
for (; ; ) {
JsonToken tok = parser.getCurrentToken();
if (tok == JsonToken.END_OBJECT) {
break;
}
if (tok == JsonToken.FIELD_NAME) {
String name = parser.getCurrentName();
tok = parser.nextToken();
if ("name" == name) {
company.setName(acceptString(tok));
} else if ("description" == name) {
company.setDescription(acceptString(tok));
} else if ("stock" == name) {
company.setStock(acceptString(tok));
} else if ("id" == name) {
company.setId(acceptLong(tok));
} else if ("rootDepartment" == name) {
company.setRootDepartment(parseDepartment());
} else {
throw new RuntimeException("not match property : " + name);
}
}
}
accept(JsonToken.END_OBJECT);
return company;
}
Aggregations