Java 类com.alibaba.fastjson.JSONException 实例源码

项目:boohee_v5.6    文件:JSONLexerBase.java   
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");
}
项目:boohee_v5.6    文件:DeserializeBeanInfo.java   
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;
}
项目:GitHub    文件:FastJsonProvider.java   
/**
 * 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);
    }
}
项目:GitHub    文件:DenyTest.java   
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);
}
项目:uavstack    文件:JavaBeanDeserializer.java   
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);
}
项目:GitHub    文件:JavaBeanInfo.java   
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;
}
项目:zhkuas_ssm_maven    文件:WeiBoUserMgm.java   
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);
    }
项目:uavstack    文件:TypeUtils.java   
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);
}
项目:GitHub    文件:ImageDeserializer.java   
@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;
}
项目:sealtalk-android-master    文件:SealUserInfoManager.java   
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;
}
项目:uavstack    文件:DeserializeBeanInfo.java   
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;
}
项目:uavstack    文件:ClassDerializer.java   
@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);
}
项目:rongyunDemo    文件:SealUserInfoManager.java   
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;
}
项目:GitHub    文件:BugTest0.java   
public void test_error_0() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("\"222A\"", Timestamp.class);
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:ColorDeserializerTest.java   
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);
}
项目:GitHub    文件:Issue1330_byte.java   
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);
}
项目:GitHub    文件:JSONScannerTest_false.java   
public void test_scan_false_1() throws Exception {
    JSONException error = null;
    try {
        JSONScanner lexer = new JSONScanner("zalse");
        lexer.scanFalse();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
项目:pay4j    文件:FanmeiResponse.java   
public <T> T getAsObject(Class<T> clazz) {
    String content = getContent();
    String contentType = getContentType();
    if (null == content || null == contentType) {
        return null;
    }
    if (contentType.contains(ContentType.APPLICATION_JSON.getMimeType())) {
        return JSON.parseObject(content, clazz);
    }
    if (contentType.contains(ContentType.APPLICATION_XML.getMimeType())
            || contentType.contains(ContentType.TEXT_XML.getMimeType())) {
        return XmlStream.fromXML(content, clazz);
    } else if (contentType.contains(ContentType.TEXT_PLAIN.getMimeType())
            || contentType.contains(ContentType.TEXT_HTML.getMimeType())) {
        try {
            return JSON.parseObject(content, clazz);
        } catch (JSONException e) {

        }
        try {
            return XmlStream.fromXML(content, clazz);
        } catch (IllegalArgumentException ex) {

        }
        throw WeixinException.of(content);
    }
    return null;
}
项目:GitHub    文件:JSONPath_array_put.java   
public void test_put_array_error_1() throws Exception {
    Exception error = null;
    try {
        JSONPath path = new JSONPath("$.values");
        path.arrayAdd(Collections.singletonMap("values", new Object()), 123);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:uavstack    文件:DefaultJSONParser.java   
public final void accept(final int token, int nextExpectToken) {
    final JSONLexer lexer = getLexer();
    if (lexer.token() == token) {
        lexer.nextToken(nextExpectToken);
    } else {
        throw new JSONException("syntax error, expect " + JSONToken.name(token) + ", actual "
                                + JSONToken.name(lexer.token()));
    }
}
项目:GitHub    文件:StackTraceElementDeserializerTest.java   
public void test_stack_error_10() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("{\"lineNumber\":true}", StackTraceElement.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:JSONScannerTest_false.java   
public void test_scan_false_4() throws Exception {
    JSONException error = null;
    try {
        JSONScanner lexer = new JSONScanner("falze");
        lexer.scanFalse();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:JSONScannerTest_true.java   
public void test_scan_true_5() throws Exception {
    JSONException error = null;
    try {
        JSONScanner lexer = new JSONScanner("truee");
        lexer.scanTrue();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:DefaultExtJSONParserTest_0.java   
public void test_error_4() throws Exception {
    JSONException error = null;
    try {
        DefaultJSONParser parser = new DefaultJSONParser(
                "[\"age\":33}");
        parser.parseObject(new User());
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:DateTest_error.java   
public void test_error_4() throws Exception {
    String text = "{\"@type\":\"java.util.Date\",1:true}";

    Exception error = null;
    try {
        JSON.parseObject(text);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:ListStringFieldTest_dom.java   
public void test_error_2() throws Exception {
    String text = "{\"model\":{\"values\":[][";


    Exception error = null;
    try {
        JSON.parseObject(text, new TypeReference<Map<String, Model>>() {
        });
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:DateTest_error.java   
public void test_error_2() throws Exception {
    String text = "{\"@type\":\"java.util.Date\",\"value\":true}";

    Exception error = null;
    try {
        JSON.parseObject(text, Date.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:ColorDeserializerTest.java   
public void test_error_2() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("{\"r\":44.}", Color.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:TPondof    文件:UserItemManager.java   
public static User getUserInfo (int uid, JSONObject object, boolean loadFull) throws APIException {
    if (mCachedUsers.containsKey(uid)) {
        // TODO: 这里会缓存 简短的用户信息 ,当获取完整信息时也会取出缓存。
        return mCachedUsers.get(uid);
    }
    try {
        JSONObject data = object.getJSONObject("data");
        User user = new User();
        user.setId(uid);
        JSONObject attributes;
        if (loadFull) {
            attributes = data.getJSONObject("attributes");
        } else {
            attributes = object.getJSONObject("attributes");
        }
        user.setUsername(attributes.getString("username"));
        user.setAvatarUrl(attributes.getString("avatarUrl"));
        if (loadFull) {
            user.setBio(attributes.getString("bio"));
            user.setJoinTime(attributes.getString("joinTime"));
            user.setDiscussionsCount(attributes.getInteger("discussionsCount"));
            user.setCommentsCount(attributes.getInteger("commentsCount"));
            user.setCanEdit(attributes.getBoolean("canEdit"));
            user.setCanDelete(attributes.getBoolean("canDelete"));
            user.setCanSuspend(attributes.getBoolean("canSuspend"));
            user.setVingleShareSocial(attributes.getString("vingle.share.social"));
            //TODO:Group
        }
        mCachedUsers.put(uid, user);
        return user;
    } catch (JSONException e) {
        throw new APIException(e);
    }
}
项目:asura    文件:SOAResParseUtil.java   
/**
 * 获取返回的JSON对象
 *
 * @param result
 * @return
 * @author xuxiao
 * @created 2014年5月7日 下午5:59:58
 */
public static JSONObject getJsonObj(final String result) {
    try {
        return JSON.parseObject(result);
    } catch (final JSONException e) {
        LOGGER.error("解析SOA返回JSON结果错误!", e);
        return null;
    }
}
项目:GitHub    文件:JSONScannerTest_new.java   
public void test_scan_new_6() throws Exception {
    JSONException error = null;
    try {
        JSONScanner lexer = new JSONScanner("new\"");
        lexer.scanNullOrNew();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:BeanToArrayTest_long.java   
public void test_long_error() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("[-", Model.class, Feature.SupportArrayToBean);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:boohee_v5.6    文件:JSONLexerBase.java   
public final void scanNullOrNew() {
    if (this.ch != 'n') {
        throw new JSONException("error parse null or new");
    }
    next();
    if (this.ch == 'u') {
        next();
        if (this.ch != 'l') {
            throw new JSONException("error parse true");
        }
        next();
        if (this.ch != 'l') {
            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 = 8;
            return;
        }
        throw new JSONException("scan true error");
    } else if (this.ch != 'e') {
        throw new JSONException("error parse e");
    } else {
        next();
        if (this.ch != 'w') {
            throw new JSONException("error parse w");
        }
        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 = 9;
            return;
        }
        throw new JSONException("scan true error");
    }
}
项目:GitHub    文件:JSONScannerTest_scanFieldDouble.java   
public void test_error_2() throws Exception {
    JSONException error = null;
    try {
        String text = "{\"value\":32K}";
        JSON.parseObject(text, VO.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:SerializeWriter.java   
public void expandCapacity(int minimumCapacity) {
    if (maxBufSize != -1 && minimumCapacity >= maxBufSize) {
        throw new JSONException("serialize exceeded MAX_OUTPUT_LENGTH=" + maxBufSize + ", minimumCapacity=" + minimumCapacity);
    }

    int newCapacity = buf.length + (buf.length >> 1) + 1;

    if (newCapacity < minimumCapacity) {
        newCapacity = minimumCapacity;
    }
    char newValue[] = new char[newCapacity];
    System.arraycopy(buf, 0, newValue, 0, count);
    buf = newValue;
}
项目:GitHub    文件:ListStringFieldTest_stream_array.java   
public void test_error_fnull() throws Exception {
    String text = "[[null";
    JSONReader reader = new JSONReader(new StringReader(text));

    Exception error = null;
    try {
        reader.readObject(Model.class);
        reader.close();
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:ListStringFieldTest_stream_array.java   
public void test_error_nu() throws Exception {
    String text = "[nu";
    JSONReader reader = new JSONReader(new StringReader(text));

    Exception error = null;
    try {
        reader.readObject(Model.class);
        reader.close();
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:FontDeserializerTest.java   
public void test_stack_error_2() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("{\"name\":22}", Font.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:uavstack    文件:TimestampDeserializer.java   
@SuppressWarnings("unchecked")
protected <T> T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {

    if (val == null) {
        return null;
    }

    if (val instanceof java.util.Date) {
        return (T) new java.sql.Timestamp(((Date) val).getTime());
    }

    if (val instanceof Number) {
        return (T) new java.sql.Timestamp(((Number) val).longValue());
    }

    if (val instanceof String) {
        String strVal = (String) val;
        if (strVal.length() == 0) {
            return null;
        }

        DateFormat dateFormat = parser.getDateFormat();
        try {
            Date date = (Date) dateFormat.parse(strVal);
            return (T) new Timestamp(date.getTime());
        } catch (ParseException e) {
            // skip
        }

        long longVal = Long.parseLong(strVal);
        return (T) new java.sql.Timestamp(longVal);
    }

    throw new JSONException("parse error");
}
项目:GitHub    文件:LongCodec.java   
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    final JSONLexer lexer = parser.lexer;

    Long longObject;
    try {
        final int token = lexer.token();
        if (token == JSONToken.LITERAL_INT) {
            long longValue = lexer.longValue();
            lexer.nextToken(JSONToken.COMMA);
            longObject = Long.valueOf(longValue);
        } else {
            if (token == JSONToken.LBRACE) {
                JSONObject jsonObject = new JSONObject(true);
                parser.parseObject(jsonObject);
                longObject = TypeUtils.castToLong(jsonObject);
            } else {
                Object value = parser.parse();

                longObject = TypeUtils.castToLong(value);
            }
            if (longObject == null) {
                return null;
            }
        }
    } catch (Exception ex) {
        throw new JSONException("parseLong error, field : " + fieldName, ex);
    }

    return clazz == AtomicLong.class //
        ? (T) new AtomicLong(longObject.longValue()) //
        : (T) longObject;
}