本文整理汇总了Java中com.alibaba.fastjson.JSONException类的典型用法代码示例。如果您正苦于以下问题:Java JSONException类的具体用法?Java JSONException怎么用?Java JSONException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONException类属于com.alibaba.fastjson包,在下文中一共展示了JSONException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanTrue
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public final void scanTrue() {
if (this.ch != 't') {
throw new JSONException("error parse true");
}
next();
if (this.ch != 'r') {
throw new JSONException("error parse true");
}
next();
if (this.ch != 'u') {
throw new JSONException("error parse true");
}
next();
if (this.ch != 'e') {
throw new JSONException("error parse true");
}
next();
if (this.ch == ' ' || this.ch == ',' || this.ch == '}' || this.ch == ']' || this.ch == '\n' || this.ch == '\r' || this.ch == '\t' || this.ch == '\u001a' || this.ch == '\f' || this.ch == '\b') {
this.token = 6;
return;
}
throw new JSONException("scan true error");
}
示例2: getCreatorConstructor
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public static Constructor<?> getCreatorConstructor(Class<?> clazz) {
Constructor[] declaredConstructors = clazz.getDeclaredConstructors();
int length = declaredConstructors.length;
int i = 0;
while (i < length) {
Constructor<?> constructor = declaredConstructors[i];
if (((JSONCreator) constructor.getAnnotation(JSONCreator.class)) == null) {
i++;
} else if (null == null) {
return constructor;
} else {
throw new JSONException("multi-json creator");
}
}
return null;
}
示例3: readFrom
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
/**
* Method that JAX-RS container calls to deserialize given value.
*/
public Object readFrom(Class<Object> type, //
Type genericType, //
Annotation[] annotations, //
MediaType mediaType, //
MultivaluedMap<String, String> httpHeaders, //
InputStream entityStream) throws IOException, WebApplicationException {
try {
FastJsonConfig fastJsonConfig = locateConfigProvider(type, mediaType);
return JSON.parseObject(entityStream, fastJsonConfig.getCharset(), genericType, fastJsonConfig.getFeatures());
} catch (JSONException ex) {
throw new WebApplicationException("JSON parse error: " + ex.getMessage(), ex);
}
}
示例4: test_0
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public void test_0() throws Exception {
String text = "{}";
ParserConfig config = new ParserConfig();
config.addDeny(null);
config.addDeny("com.alibaba.json.bvtVO.deny");
Exception error = null;
try {
JSON.parseObject("{\"@type\":\"com.alibaba.json.bvtVO.deny$A\"}", Object.class, config, JSON.DEFAULT_PARSER_FEATURE);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
JSON.parseObject(text, B.class, config, JSON.DEFAULT_PARSER_FEATURE);
}
示例5: parseExtra
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
void parseExtra(DefaultJSONParser parser, Object object, String key) {
final JSONLexer lexer = parser.getLexer(); // xxx
if (!lexer.isEnabled(Feature.IgnoreNotMatch)) {
throw new JSONException("setter not found, class " + clazz.getName() + ", property " + key);
}
lexer.nextTokenWithColon();
Type type = FilterUtils.getExtratype(parser, object, key);
Object value;
if (type == null) {
value = parser.parse(); // skip
} else {
value = parser.parseObject(type);
}
FilterUtils.processExtra(parser, object, key, value);
}
示例6: getFactoryMethod
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
private static Method getFactoryMethod(Class<?> clazz, Method[] methods) {
Method factoryMethod = null;
for (Method method : methods) {
if (!Modifier.isStatic(method.getModifiers())) {
continue;
}
if (!clazz.isAssignableFrom(method.getReturnType())) {
continue;
}
JSONCreator annotation = method.getAnnotation(JSONCreator.class);
if (annotation != null) {
if (factoryMethod != null) {
throw new JSONException("multi-JSONCreator");
}
factoryMethod = method;
// 不应该break,否则多个静态工厂方法上存在 JSONCreator 注解时,并不会触发上述异常抛出
}
}
return factoryMethod;
}
示例7: getAccessTokenByCode
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public AccessToken getAccessTokenByCode(String code) throws WeiboException, JSONException{
Map<String,String> params =new HashMap<String,String>();
params.put("client_id", WebConfigUtils.getValue("client_ID"));
params.put("client_secret", WebConfigUtils.getValue("client_SERCRET"));
params.put("grant_type", "authorization_code");
params.put("code",code);
params.put("redirect_uri", new StringBuilder().append(WebConfigUtils.getValue("rz_host")).append("/").append(WebConfigUtils.getValue("redirect_URI")).toString());
fetchUrl.setPostData(params);
String res = null;
try {
res = fetchUrl.post(WebConfigUtils.getValue("accessTokenURL"),Constants.MAX_FETCHURL_COUNT);
} catch (FetchTimeoutException e) {
// e.printStackTrace();
logger.info(e.getMessage());
}
// String res =new HttpClientUtils().sendPostSSLRequest(WebConfigUtils.getValue("accessTokenURL"), params);
return new AccessToken(res);
}
示例8: castToChar
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public static final Character castToChar(Object value) {
if (value == null) {
return null;
}
if (value instanceof Character) {
return (Character) value;
}
if (value instanceof String) {
String strVal = (String) value;
if (strVal.length() == 0) {
return null;
}
if (strVal.length() != 1) {
throw new JSONException("can not cast to byte, value : " + value);
}
return strVal.charAt(0);
}
throw new JSONException("can not cast to byte, value : " + value);
}
示例9: deserialze
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
Image image = new Image();
final JSONLexer lexer = parser.getLexer();
if (lexer.token() != JSONToken.LBRACKET) {
throw new JSONException("error");
}
int height = lexer.scanInt(',');
int width = lexer.scanInt(',');
String sizeName = lexer.scanSymbolWithSeperator(parser.getSymbolTable(), ',');
String title = lexer.scanString(',');
String uri = lexer.scanString(']');
lexer.nextToken(JSONToken.COMMA);
image.setHeight(height);
image.setWidth(width);
image.setSize(Size.valueOf(sizeName));
image.setTitle(title);
image.setUri(uri);
return (T) image;
}
示例10: fetchGroups
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
private boolean fetchGroups() throws HttpException {
GetGroupResponse groupResponse;
try {
groupResponse = action.getGroups();
} catch (JSONException e) {
NLog.d(TAG, "fetchGroups occurs JSONException e=" + e.toString());
return true;
}
if (groupResponse != null && groupResponse.getCode() == 200) {
List<GetGroupResponse.ResultEntity> groupsList = groupResponse.getResult();
if (groupsList != null && groupsList.size() > 0) {
syncDeleteGroups();
addGroups(groupsList);
}
mGetAllUserInfoState |= GROUPS;
return true;
}
return false;
}
示例11: getCreatorConstructor
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public static Constructor<?> getCreatorConstructor(Class<?> clazz) {
Constructor<?> creatorConstructor = null;
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
JSONCreator annotation = constructor.getAnnotation(JSONCreator.class);
if (annotation != null) {
if (creatorConstructor != null) {
throw new JSONException("multi-json creator");
}
creatorConstructor = constructor;
break;
}
}
return creatorConstructor;
}
示例12: deserialze
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == JSONToken.NULL) {
lexer.nextToken();
return null;
}
if (lexer.token() != JSONToken.LITERAL_STRING) {
throw new JSONException("expect className");
}
String className = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) TypeUtils.loadClass(className);
}
示例13: test_error_0
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public void test_error_0() throws Exception {
Exception error = null;
try {
JSON.parseObject("\"222A\"", Timestamp.class);
} catch (JSONException e) {
error = e;
}
Assert.assertNotNull(error);
}
示例14: test_error_3
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public void test_error_3() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"x\":44}", Color.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例15: test_for_issue
import com.alibaba.fastjson.JSONException; //导入依赖的package包/类
public void test_for_issue() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"value\":\"ABC\"}", Model.class);
} catch (JSONException e) {
error = e;
}
assertNotNull(error);
assertTrue(error.getMessage().indexOf("parseByte error, field : value") != -1);
}