public VPackSlice fromJson(final String json, final boolean includeNullValues) throws VPackException { final VPackBuilder builder = new VPackBuilder(); final JSONParser parser = new JSONParser(); final ContentHandler contentHandler = new VPackContentHandler(builder, includeNullValues, this); try { parser.parse(json, contentHandler); } catch (final ParseException e) { throw new VPackBuilderException(e); } return builder.slice(); }
public VPackSlice fromJson(final Iterable<String> jsons, final boolean includeNullValues) throws VPackException { final VPackBuilder builder = new VPackBuilder(); final JSONParser parser = new JSONParser(); final ContentHandler contentHandler = new VPackContentHandler(builder, includeNullValues, this); try { builder.add(ValueType.ARRAY); for (final String json : jsons) { parser.parse(json, contentHandler); } builder.close(); } catch (final ParseException e) { throw new VPackBuilderException(e); } return builder.slice(); }
protected ContentHandler getContentHandler() { return new BaseContentHandler() { public boolean primitive(Object value) throws ParseException, IOException { String key = (String) objects.peek(); if ("text".equals(key)) { query = (String) value; } else if ("id".equals(key)) { String parentKey = (String) objects.elementAt(objects.size() - 2); if ("persons".equals(parentKey)) { persons++; } else if ("texts".equals(parentKey)) { texts++; } else if ("books".equals(parentKey)) { books++; } else if ("series".equals(parentKey)) { series++; } else if ("sequences".equals(parentKey)) { sequences++; } else if ("labels".equals(parentKey)) { labels++; } else if ("categories".equals(parentKey)) { categories++; } } return true; } }; }
protected ContentHandler getContentHandler() { return new BaseContentHandler() { public boolean endArray() throws ParseException, IOException { return !SERIES_KEY.equals(getParentKey()); } public boolean startObject() throws ParseException, IOException { if (SERIES_KEY.equals(getParentKey())) { series.add(new Serie()); } return true; } public boolean primitive(Object value) throws ParseException, IOException { String key = (String) objects.peek(); if ("slug".equals(key)) { if (SERIES_KEY.equals(getParentKey(2))) { getLast().setSlug((String) value); } } else if ("name".equals(key)) { if (SERIES_KEY.equals(getParentKey(2))) { getLast().setName((String) value); } } return true; } }; }
protected ContentHandler getContentHandler() { return new BaseContentHandler() { public boolean endArray() throws ParseException, IOException { return !TEXTS_KEY.equals(getParentKey()); } public boolean startObject() throws ParseException, IOException { if (TEXTS_KEY.equals(getParentKey())) { texts.add(new Text()); } return true; } public boolean primitive(Object value) throws ParseException, IOException { String key = (String) objects.peek(); if ("id".equals(key)) { if (TEXTS_KEY.equals(getParentKey(2))) { getLast().setId(((Long) value).intValue()); } } else if ("title".equals(key)) { if (TEXTS_KEY.equals(getParentKey(2))) { getLast().setTitle((String) value); } } return true; } }; }
protected ContentHandler getContentHandler() { return new BaseContentHandler() { public boolean endArray() throws ParseException, IOException { return !SEQUENCES_KEY.equals(getParentKey()); } public boolean startObject() throws ParseException, IOException { if (SEQUENCES_KEY.equals(getParentKey())) { sequences.add(new Sequence()); } return true; } public boolean primitive(Object value) throws ParseException, IOException { String key = (String) objects.peek(); if ("slug".equals(key)) { if (SEQUENCES_KEY.equals(getParentKey(2))) { getLast().setSlug((String) value); } } else if ("name".equals(key)) { if (SEQUENCES_KEY.equals(getParentKey(2))) { getLast().setName((String) value); } } else if ("nrOfBooks".equals(key)) { if (SEQUENCES_KEY.equals(getParentKey(2))) { getLast().setNumberOfBooks(((Long) value).intValue()); } } return true; } }; }
protected ContentHandler getContentHandler() { return new BaseContentHandler() { public boolean endArray() throws ParseException, IOException { return !LABELS_KEY.equals(getParentKey()); } public boolean startObject() throws ParseException, IOException { if (LABELS_KEY.equals(getParentKey())) { labels.add(new Label()); } return true; } public boolean primitive(Object value) throws ParseException, IOException { String key = (String) objects.peek(); if ("slug".equals(key)) { if (LABELS_KEY.equals(getParentKey(2))) { getLast().setSlug((String) value); } } else if ("name".equals(key)) { if (LABELS_KEY.equals(getParentKey(2))) { getLast().setName((String) value); } } else if ("nrOfTexts".equals(key)) { if (LABELS_KEY.equals(getParentKey(2))) { getLast().setNumberOfTexts(((Long) value).intValue()); } } return true; } }; }
protected ContentHandler getContentHandler() { return new BaseContentHandler() { public boolean endArray() throws ParseException, IOException { return !CATEGORIES_KEY.equals(getParentKey()); } public boolean startObject() throws ParseException, IOException { if (CATEGORIES_KEY.equals(getParentKey())) { categories.add(new Category()); } return true; } public boolean primitive(Object value) throws ParseException, IOException { String key = (String) objects.peek(); if ("slug".equals(key)) { if (CATEGORIES_KEY.equals(getParentKey(2))) { getLast().setSlug((String) value); } } else if ("name".equals(key)) { if (CATEGORIES_KEY.equals(getParentKey(2))) { getLast().setName((String) value); } } else if ("nrOfBooks".equals(key)) { if (CATEGORIES_KEY.equals(getParentKey(2))) { getLast().setNumberOfBooks(((Long) value).intValue()); } } return true; } }; }
protected ContentHandler getContentHandler() { return new BaseContentHandler() { public boolean endArray() throws ParseException, IOException { return !PERSONS_KEY.equals(getParentKey()); } public boolean startObject() throws ParseException, IOException { if (PERSONS_KEY.equals(getParentKey())) { persons.add(new Person()); } return true; } public boolean primitive(Object value) throws ParseException, IOException { String key = (String) objects.peek(); if ("slug".equals(key)) { if (PERSONS_KEY.equals(getParentKey(2))) { getLast().setSlug((String) value); } } else if ("name".equals(key)) { if (PERSONS_KEY.equals(getParentKey(2))) { getLast().setName((String) value); } } else if ("isAuthor".equals(key)) { if (PERSONS_KEY.equals(getParentKey(2))) { getLast().setAuthor(((Boolean) value).booleanValue()); } } return true; } }; }
public void handleSubs(boolean unread, int fromId, int limit, ContentHandler handler) throws IOException, ParseException, ReaderException { new JSONParser().parse(readSubs(unread, fromId, limit), handler); }
public void handleAll(long subId, int offset, int limit, ContentHandler handler) throws IOException, ParseException, ReaderException { new JSONParser().parse(readAll(subId, offset, limit), handler); }
public void handleUnread(long subId, ContentHandler handler) throws IOException, ParseException, ReaderException { new JSONParser().parse(readUnread(subId), handler); }
public void handlePinAll(ContentHandler handler) throws IOException, ParseException, ReaderException { new JSONParser().parse(readPinAll(), handler); }
protected abstract ContentHandler getContentHandler();