Search in sources :

Example 1 with JsonToken

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);
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) CookieContainer(com.github.dreamhead.moco.parser.model.CookieContainer)

Example 2 with JsonToken

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);
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) FileContainer.asFileContainer(com.github.dreamhead.moco.parser.model.FileContainer.asFileContainer) FileContainer(com.github.dreamhead.moco.parser.model.FileContainer) FileContainer.aFileContainer(com.github.dreamhead.moco.parser.model.FileContainer.aFileContainer)

Example 3 with JsonToken

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;
    }
}
Also used : InputStream(java.io.InputStream) HttpHost(org.apache.http.HttpHost) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 4 with JsonToken

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;
}
Also used : Department(com.alibaba.json.test.entity.Department) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 5 with JsonToken

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;
}
Also used : Company(com.alibaba.json.test.entity.Company) JsonToken(com.fasterxml.jackson.core.JsonToken)

Aggregations

JsonToken (com.fasterxml.jackson.core.JsonToken)46 JsonParser (com.fasterxml.jackson.core.JsonParser)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)8 SqlNullable (com.facebook.presto.spi.function.SqlNullable)7 SqlType (com.facebook.presto.spi.function.SqlType)7 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)7 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 JsonParserHelper.assertExpectedJsonToken (com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken)5 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 RpcHint (com.navercorp.pinpoint.web.filter.RpcHint)2 InputStream (java.io.InputStream)2 ValueSerializationException (org.qi4j.api.value.ValueSerializationException)2 Company (com.alibaba.json.test.entity.Company)1 Department (com.alibaba.json.test.entity.Department)1 Employee (com.alibaba.json.test.entity.Employee)1 Group (com.alibaba.json.test.entity.Group)1 LayoutInstance (com.alibaba.json.test.entity.pagemodel.LayoutInstance)1 PageInstance (com.alibaba.json.test.entity.pagemodel.PageInstance)1