Package argo.staj

Examples of argo.staj.JsonStreamElement


    public void parsesUsingStaj() throws Exception {
        final FileReader jsonReader = new FileReader(new File(this.getClass().getResource("SimpleExample.json").getFile()));
        Set<String> fieldNames = new HashSet<String>();
        final StajParser stajParser = new StajParser(jsonReader);
        while (stajParser.hasNext()) {
            JsonStreamElement next = stajParser.next();
            if (next.jsonStreamElementType() == JsonStreamElementType.START_FIELD) {
                fieldNames.add(next.text());
            }
        }
        assertThat(fieldNames, equalTo((Set<String>) new HashSet<String>(Arrays.asList("name", "sales", "totalRoyalties", "singles"))));
    }
View Full Code Here


    }

    void parse(final JsonListener jsonListener, final StajParser stajParser) throws InvalidSyntaxException {
        try {
            while (stajParser.hasNext()) {
                final JsonStreamElement jsonStreamElement = stajParser.next();
                switch (jsonStreamElement.jsonStreamElementType()) {
                    case START_DOCUMENT:
                        jsonListener.startDocument();
                        break;
                    case END_DOCUMENT:
                        jsonListener.endDocument();
                        break;
                    case START_ARRAY:
                        jsonListener.startArray();
                        break;
                    case END_ARRAY:
                        jsonListener.endArray();
                        break;
                    case START_OBJECT:
                        jsonListener.startObject();
                        break;
                    case END_OBJECT:
                        jsonListener.endObject();
                        break;
                    case START_FIELD:
                        jsonListener.startField(jsonStreamElement.text());
                        break;
                    case END_FIELD:
                        jsonListener.endField();
                        break;
                    case NULL:
                        jsonListener.nullValue();
                        break;
                    case TRUE:
                        jsonListener.trueValue();
                        break;
                    case FALSE:
                        jsonListener.falseValue();
                        break;
                    case STRING:
                        jsonListener.stringValue(jsonStreamElement.text());
                        break;
                    case NUMBER:
                        jsonListener.numberValue(jsonStreamElement.text());
                        break;
                    default:
                        throw new IllegalStateException("Got a JsonStreamElement of unexpected type: " + jsonStreamElement);
                }
            }
View Full Code Here

TOP

Related Classes of argo.staj.JsonStreamElement

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.