Search in sources :

Example 11 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class LexerTest method test_big_integer_2.

public void test_big_integer_2() throws Exception {
    String text = Long.MIN_VALUE + "1234";
    JSONScanner lexer = new JSONScanner(text);
    lexer.nextToken();
    Assert.assertEquals(new BigInteger(text), lexer.integerValue());
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) BigInteger(java.math.BigInteger)

Example 12 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class LexerTest method test_error2.

public void test_error2() {
    Exception error = null;
    try {
        JSONScanner lexer = new JSONScanner("--");
        lexer.nextToken();
        lexer.integerValue();
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 13 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class Issue119 method test_for_issue_b.

public void test_for_issue_b() throws Exception {
    JSONScanner lexer = new JSONScanner("-10B");
    lexer.scanNumber();
    Assert.assertEquals(Byte.class, lexer.integerValue().getClass());
    Assert.assertEquals(-10, lexer.integerValue().byteValue());
    lexer.close();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 14 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONLexerTest_8 method test_ident.

public void test_ident() throws Exception {
    JSONScanner lexer = new JSONScanner("123");
    lexer.nextIdent();
    org.junit.Assert.assertEquals(JSONToken.LITERAL_INT, lexer.token());
    lexer.close();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 15 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONReaderTest_array_array method test_read_1.

public void test_read_1() throws Exception {
    JSONReader reader = new JSONReader(new JSONScanner(text));
    reader.startArray();
    int count = 0;
    while (reader.hasNext()) {
        Object item = reader.readObject();
        Assert.assertEquals(JSONArray.class, item.getClass());
        count++;
    }
    Assert.assertEquals(10, count);
    reader.endArray();
    reader.close();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) JSONReader(com.alibaba.fastjson.JSONReader)

Aggregations

JSONScanner (com.alibaba.fastjson.parser.JSONScanner)179 JSONException (com.alibaba.fastjson.JSONException)37 SymbolTable (com.alibaba.fastjson.parser.SymbolTable)15 JSONReader (com.alibaba.fastjson.JSONReader)11 ParseException (java.text.ParseException)5 BigInteger (java.math.BigInteger)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 BigDecimal (java.math.BigDecimal)1 AccessControlException (java.security.AccessControlException)1 Calendar (java.util.Calendar)1