Package com.alibaba.fastjson.parser

Examples of com.alibaba.fastjson.parser.DefaultJSONParser


        CharBuffer charBuf = CharBuffer.wrap(chars);
        IOUtils.decode(charsetDecoder, byteBuf, charBuf);

        int position = charBuf.position();

        DefaultJSONParser parser = new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features);
        Object value = parser.parse();

        handleResovleTask(parser, value);

        parser.close();

        return value;
    }
View Full Code Here


        for (Feature featrue : features) {
            featureValues = Feature.config(featureValues, featrue, true);
        }

        DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), featureValues);
        T value = (T) parser.parseObject(clazz);

        handleResovleTask(parser, value);

        parser.close();

        return (T) value;
    }
View Full Code Here

        for (Feature featrue : features) {
            featureValues = Feature.config(featureValues, featrue, true);
        }

        DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);
        T value = (T) parser.parseObject(clazz);

        handleResovleTask(parser, value);

        parser.close();

        return (T) value;
    }
View Full Code Here

        int featureValues = DEFAULT_PARSER_FEATURE;
        for (Feature featrue : features) {
            featureValues = Feature.config(featureValues, featrue, true);
        }

        DefaultJSONParser parser = new DefaultJSONParser(input, length, ParserConfig.getGlobalInstance(), featureValues);
        T value = (T) parser.parseObject(clazz);

        handleResovleTask(parser, value);

        parser.close();

        return (T) value;
    }
View Full Code Here

    public static final JSONArray parseArray(String text) {
        if (text == null) {
            return null;
        }

        DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());

        JSONArray array;

        JSONLexer lexer = parser.getLexer();
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            array = null;
        } else if (lexer.token() == JSONToken.EOF) {
            array = null;
        } else {
            array = new JSONArray();
            parser.parseArray(array);

            handleResovleTask(parser, array);
        }

        parser.close();

        return array;
    }
View Full Code Here

            return null;
        }

        List<T> list;

        DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
        JSONLexer lexer = parser.getLexer();
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            list = null;
        } else {
            list = new ArrayList<T>();
            parser.parseArray(clazz, list);

            handleResovleTask(parser, list);
        }

        parser.close();

        return list;
    }
View Full Code Here

            return null;
        }

        List<Object> list;

        DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
        Object[] objectArray = parser.parseArray(types);
        if (objectArray == null) {
            list = null;
        } else {
            list = Arrays.asList(objectArray);
        }

        handleResovleTask(parser, list);

        parser.close();

        return list;
    }
View Full Code Here

import com.alibaba.fastjson.parser.Feature;

public class DefaultJSONParserTest extends TestCase {

  public void test_double() {
    DefaultJSONParser parser = new DefaultJSONParser("3.4");
    parser.config(Feature.UseBigDecimal, false);
    Assert.assertEquals("3.4", parser.getInput());
    Assert.assertEquals(false, parser.isEnabled(Feature.UseBigDecimal));
    Object result = parser.parse();
    Assert.assertEquals(3.4D, result);
  }
View Full Code Here

  }

  public void test_error() {
    Exception error = null;
    try {
      DefaultJSONParser parser = new DefaultJSONParser("{\"name\":3]");
      parser.parse();
    } catch (Exception ex) {
      error = ex;
    }
    Assert.assertNotNull(error);
  }
View Full Code Here

  }

  public void test_error2() {
    Exception error = null;
    try {
      DefaultJSONParser parser = new DefaultJSONParser("ttr");
      parser.parse();
    } catch (Exception ex) {
      error = ex;
    }
    Assert.assertNotNull(error);
  }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.parser.DefaultJSONParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.