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;
}
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();
}
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);
}
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;
}
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;
}
Aggregations