Search in sources :

Example 51 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project fastjson by alibaba.

the class JacksonGroupParser method parseGroup.

public Group parseGroup() throws Exception {
    Group group = new Group();
    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) {
                group.setName(acceptString(tok));
            } else if ("description" == name) {
                group.setDescription(acceptString(tok));
            } else if ("companies" == name) {
                parseCompany(group.getCompanies());
            } else {
                throw new RuntimeException("not match property : " + name);
            }
        }
    }
    accept(JsonToken.END_OBJECT);
    return group;
}
Also used : Group(com.alibaba.json.test.entity.Group) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 52 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project fastjson by alibaba.

the class JacksonGroupParser method getNextTextValue.

public static String getNextTextValue(String fieldName, JsonParser parser) throws JsonParseException, IOException {
    // move to filed
    JsonToken current = parser.nextToken();
    if (current != JsonToken.FIELD_NAME || !fieldName.equals(parser.getCurrentName())) {
        reportParseError("Error occoured while getting value by field name:" + fieldName, parser.getCurrentLocation());
    }
    // move to value
    current = parser.nextToken();
    return parser.getText();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 53 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project fastjson by alibaba.

the class JacksonGroupParser method parseEmployee.

private void parseEmployee(List<Employee> list) throws Exception {
    accept(JsonToken.START_ARRAY);
    for (; ; ) {
        JsonToken tok = parser.getCurrentToken();
        if (tok == JsonToken.END_ARRAY) {
            break;
        }
        list.add(parseEmployee());
    }
    accept(JsonToken.END_ARRAY);
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 54 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project fastjson by alibaba.

the class JacksonPageModelParser method parseLayouts.

/**
     * @param parser
     * @param segmentId
     * @throws JsonParseException
     * @throws IOException
     */
private List<LayoutInstance> parseLayouts(JsonParser parser, String segment) throws JsonParseException, IOException {
    JsonToken current = parser.nextToken();
    assertExpectedJsonToken(current, JsonToken.START_ARRAY, parser.getCurrentLocation());
    List<LayoutInstance> layoutInThisSegment = new ArrayList<LayoutInstance>();
    while ((current = parser.nextToken()) != JsonToken.END_ARRAY) {
        assertExpectedJsonToken(current, JsonToken.START_OBJECT, parser.getCurrentLocation());
        // get
        String instanceId = getNextTextValue("sid", parser);
        // instanceId
        // get
        String layoutId = getNextTextValue("cid", parser);
        // layoutId
        LayoutInstance layoutInstance = new LayoutInstance();
        layoutInstance.setCid(layoutId);
        layoutInstance.setSid(Long.valueOf(instanceId));
        layoutInThisSegment.add(layoutInstance);
        // move to field: regions
        current = parser.nextToken();
        assertExpectedFiled(parser.getCurrentName(), "regions", parser.getCurrentLocation());
        layoutInstance.setRegions(parseRegions(parser, segment));
        assertExpectedJsonToken((current = parser.nextToken()), JsonToken.END_OBJECT, parser.getCurrentLocation());
    }
    return layoutInThisSegment;
}
Also used : ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParserHelper.assertExpectedJsonToken(com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken) LayoutInstance(com.alibaba.json.test.entity.pagemodel.LayoutInstance)

Example 55 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project spring-security-oauth by spring-projects.

the class OAuth2ExceptionJackson2Deserializer method deserialize.

@Override
public OAuth2Exception deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    JsonToken t = jp.getCurrentToken();
    if (t == JsonToken.START_OBJECT) {
        t = jp.nextToken();
    }
    Map<String, Object> errorParams = new HashMap<String, Object>();
    for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
        // Must point to field name
        String fieldName = jp.getCurrentName();
        // And then the value...
        t = jp.nextToken();
        // Note: must handle null explicitly here; value deserializers won't
        Object value;
        if (t == JsonToken.VALUE_NULL) {
            value = null;
        } else // Some servers might send back complex content
        if (t == JsonToken.START_ARRAY) {
            value = jp.readValueAs(List.class);
        } else if (t == JsonToken.START_OBJECT) {
            value = jp.readValueAs(Map.class);
        } else {
            value = jp.getText();
        }
        errorParams.put(fieldName, value);
    }
    Object errorCode = errorParams.get("error");
    String errorMessage = errorParams.get("error_description") != null ? errorParams.get("error_description").toString() : null;
    if (errorMessage == null) {
        errorMessage = errorCode == null ? "OAuth Error" : errorCode.toString();
    }
    OAuth2Exception ex;
    if ("invalid_client".equals(errorCode)) {
        ex = new InvalidClientException(errorMessage);
    } else if ("unauthorized_client".equals(errorCode)) {
        ex = new UnauthorizedClientException(errorMessage);
    } else if ("invalid_grant".equals(errorCode)) {
        if (errorMessage.toLowerCase().contains("redirect") && errorMessage.toLowerCase().contains("match")) {
            ex = new RedirectMismatchException(errorMessage);
        } else {
            ex = new InvalidGrantException(errorMessage);
        }
    } else if ("invalid_scope".equals(errorCode)) {
        ex = new InvalidScopeException(errorMessage);
    } else if ("invalid_token".equals(errorCode)) {
        ex = new InvalidTokenException(errorMessage);
    } else if ("invalid_request".equals(errorCode)) {
        ex = new InvalidRequestException(errorMessage);
    } else if ("redirect_uri_mismatch".equals(errorCode)) {
        ex = new RedirectMismatchException(errorMessage);
    } else if ("unsupported_grant_type".equals(errorCode)) {
        ex = new UnsupportedGrantTypeException(errorMessage);
    } else if ("unsupported_response_type".equals(errorCode)) {
        ex = new UnsupportedResponseTypeException(errorMessage);
    } else if ("insufficient_scope".equals(errorCode)) {
        ex = new InsufficientScopeException(errorMessage, OAuth2Utils.parseParameterList((String) errorParams.get("scope")));
    } else if ("access_denied".equals(errorCode)) {
        ex = new UserDeniedAuthorizationException(errorMessage);
    } else {
        ex = new OAuth2Exception(errorMessage);
    }
    Set<Map.Entry<String, Object>> entries = errorParams.entrySet();
    for (Map.Entry<String, Object> entry : entries) {
        String key = entry.getKey();
        if (!"error".equals(key) && !"error_description".equals(key)) {
            Object value = entry.getValue();
            ex.addAdditionalInformation(key, value == null ? null : value.toString());
        }
    }
    return ex;
}
Also used : HashMap(java.util.HashMap) JsonToken(com.fasterxml.jackson.core.JsonToken) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

JsonToken (com.fasterxml.jackson.core.JsonToken)72 JsonParser (com.fasterxml.jackson.core.JsonParser)14 IOException (java.io.IOException)14 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 JsonParseException (com.fasterxml.jackson.core.JsonParseException)3 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)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