com.alibaba.fastjson.JSONReader Java Examples
The following examples show how to use
com.alibaba.fastjson.JSONReader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSONFileRegionDataInput.java From addrparser with Apache License 2.0 | 6 votes |
@Override public void init() throws IOException { if (initialized) { return; } synchronized (this) { if (initialized) { return; } if (this.filename == null) { this.reader = new JSONReader(this._reader); } else { this.reader = new JSONReader(new FileReader(this.filename)); } this.reader.startArray(); this.initialized = true; } }
Example #2
Source File: JSONBinary.java From clouddisk with MIT License | 6 votes |
public <T> List<T> readListForDisk(final Class<T> clazz) { final List<T> lists = new ArrayList<>(0); if (StringUtils.isNotBlank(binaryFilename)) { final File file = new File(getBianaryFilenamePath()); if (!file.exists()) { throw new CloudDiskException("读取的文件:[ " + file.getAbsolutePath() + " ]不存在"); } try (JSONReader jsonReader=new JSONReader(new FileReader(file))){ jsonReader.startArray(); while (jsonReader.hasNext()) { lists.add(jsonReader.readObject(clazz)); } jsonReader.endArray(); } catch (IOException e) { LOGGER.error(ERROR,e); } return lists; } throw new CloudDiskException("读取的对象集合文件位置与文件名不能为空"); }
Example #3
Source File: AbstractSerializer.java From joyrpc with Apache License 2.0 | 5 votes |
/** * 解析对象数组 * * @param parser 解析器 * @param lexer 语法 * @param types 类型 * @param field 字段 */ protected Object[] parseObjects(final DefaultJSONParser parser, final JSONLexer lexer, final Type[] types, final String field) { Object[] result = null; //空数组 if (lexer.token() == JSONToken.NULL) { if (types.length == 0) { lexer.nextToken(); } else { throw new SerializerException("syntax error: invalid " + field); } } else { //解析参数 JSONReader reader = new JSONReader(parser); reader.startArray(); int i = 0; result = new Object[types.length]; while (reader.hasNext()) { if (i >= result.length) { throw new SerializerException("syntax error: invalid " + field); } result[i] = reader.readObject(types[i]); i++; } reader.endArray(); } return result; }