Package org.codehaus.jackson

Examples of org.codehaus.jackson.JsonParser


    private Map<String, String> parseJSON(String jsonmessage){
        Map<String, String> parsed = new HashMap<String, String>();
        JsonFactory jf = new JsonFactory();
        try {
            JsonParser parser = jf.createJsonParser(jsonmessage);
            parser.nextToken(); //shift past the START_OBJECT that begins the JSON
            while (parser.nextToken() != JsonToken.END_OBJECT) {
                String fieldname = parser.getCurrentName();
                parser.nextToken(); // move to value, or START_OBJECT/START_ARRAY
                String value = parser.getText();
                parsed.put(fieldname, value);
            }
        } catch (JsonParseException e) {
            // JSON could not be parsed
            e.printStackTrace();
View Full Code Here


                JSONObject firstFileRecord = fileRecords.get(0);
                File file = ImportingUtilities.getFile(job, firstFileRecord);
                InputStream is = new FileInputStream(file);
                try {
                    JsonFactory factory = new JsonFactory();
                    JsonParser parser = factory.createJsonParser(is);

                    PreviewParsingState state = new PreviewParsingState();
                    Object rootValue = parseForPreview(parser, state);
                    if (rootValue != null) {
                        JSONUtilities.safePut(options, "dom", rootValue);
View Full Code Here

        writer.endObject();
    }
   
    static public Recon loadStreaming(String s, Pool pool) throws Exception {
        JsonFactory jsonFactory = new JsonFactory();
        JsonParser jp = jsonFactory.createJsonParser(s);
       
        if (jp.nextToken() != JsonToken.START_OBJECT) {
            return null;
        }
        return loadStreaming(jp, pool);
    }
View Full Code Here

        }
    }
   
    static public Cell loadStreaming(String s, Pool pool) throws Exception {
        JsonFactory jsonFactory = new JsonFactory();
        JsonParser jp = jsonFactory.createJsonParser(s);
       
        if (jp.nextToken() != JsonToken.START_OBJECT) {
            return null;
        }
       
        return loadStreaming(jp, pool);
    }
View Full Code Here

        writer.endObject();
    }
   
    static public ReconCandidate loadStreaming(String s) throws Exception {
        JsonFactory jsonFactory = new JsonFactory();
        JsonParser jp = jsonFactory.createJsonParser(s);
       
        if (jp.nextToken() != JsonToken.START_OBJECT) {
            return null;
        }
        return loadStreaming(jp);
    }
View Full Code Here

            loadStreaming(s, pool);
    }
   
    static public Row loadStreaming(String s, Pool pool) throws Exception {
        JsonFactory jsonFactory = new JsonFactory();
        JsonParser jp = jsonFactory.createJsonParser(s);
       
        if (jp.nextToken() != JsonToken.START_OBJECT) {
            return null;
        }
       
        List<Cell>  cells = new ArrayList<Cell>();
        boolean     starred = false;
        boolean     flagged = false;
       
        while (jp.nextToken() != JsonToken.END_OBJECT) {
            String fieldName = jp.getCurrentName();
            jp.nextToken();
           
            if (STARRED.equals(fieldName)) {
                starred = jp.getBooleanValue();
            } else if (FLAGGED.equals(fieldName)) {
                flagged = jp.getBooleanValue();
            } else if ("cells".equals(fieldName)) {
                if (jp.getCurrentToken() != JsonToken.START_ARRAY) {
                    return null;
                }
               
                while (jp.nextToken() != JsonToken.END_ARRAY) {
                    Cell cell = Cell.loadStreaming(jp, pool);
                   
                    cells.add(cell);
                }
            }
View Full Code Here

    private void _testIsNextTokenName1(boolean useStream) throws Exception
    {
        final String DOC = "{\"name\":123,\"name2\":14,\"x\":\"name\"}";
        JsonFactory jf = new JsonFactory();
        JsonParser jp = useStream ?
            jf.createJsonParser(new ByteArrayInputStream(DOC.getBytes("UTF-8")))
            : jf.createJsonParser(new StringReader(DOC));
        SerializedString NAME = new SerializedString("name");
        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.START_OBJECT, jp.getCurrentToken());
        assertTrue(jp.nextFieldName(NAME));
        assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
        assertEquals(NAME.getValue(), jp.getCurrentName());
        assertEquals(NAME.getValue(), jp.getText());
        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.VALUE_NUMBER_INT, jp.getCurrentToken());
        assertEquals(123, jp.getIntValue());

        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
        assertEquals("name2", jp.getCurrentName());
        assertToken(JsonToken.VALUE_NUMBER_INT, jp.nextToken());

        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
        assertEquals("x", jp.getCurrentName());

        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.VALUE_STRING, jp.getCurrentToken());

        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.END_OBJECT, jp.getCurrentToken());

        assertFalse(jp.nextFieldName(NAME));
        assertNull(jp.getCurrentToken());

        jp.close();
    }
View Full Code Here

    private void _testIsNextTokenName2(boolean useStream) throws Exception
    {
        final String DOC = "{\"name\":123,\"name2\":14,\"x\":\"name\"}";
        JsonFactory jf = new JsonFactory();
        JsonParser jp = useStream ?
            jf.createJsonParser(new ByteArrayInputStream(DOC.getBytes("UTF-8")))
            : jf.createJsonParser(new StringReader(DOC));
        SerializableString NAME = new SerializedString("name");
        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.START_OBJECT, jp.getCurrentToken());
        assertTrue(jp.nextFieldName(NAME));
        assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
        assertEquals(NAME.getValue(), jp.getCurrentName());
        assertEquals(NAME.getValue(), jp.getText());
        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.VALUE_NUMBER_INT, jp.getCurrentToken());
        assertEquals(123, jp.getIntValue());

        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
        assertEquals("name2", jp.getCurrentName());
        assertToken(JsonToken.VALUE_NUMBER_INT, jp.nextToken());

        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
        assertEquals("x", jp.getCurrentName());

        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.VALUE_STRING, jp.getCurrentToken());

        assertFalse(jp.nextFieldName(NAME));
        assertToken(JsonToken.END_OBJECT, jp.getCurrentToken());

        assertFalse(jp.nextFieldName(NAME));
        assertNull(jp.getCurrentToken());

        jp.close();
    }
View Full Code Here

    OperatorFactoryLocal engine = OperatorFactoryLocal.getInstance();
    OperatorImportFromJson importerJSON = (OperatorImportFromJson) engine
        .getOperator(Operator.Type.ImportMapGeometryFromJson);

    JsonFactory jf = new JsonFactory();
    JsonParser jp = null;
    try {
      jp = jf.createJsonParser(jsonString);
      jp.nextToken();
    } catch (Exception ex) {
    }
    MapGeometry mapGeom = importerJSON.execute(Geometry.Type.Unknown, jp);
    return mapGeom;
  }
View Full Code Here

  }

  public static OGCGeometry fromJson(String string)
      throws JsonParseException, IOException {
    JsonFactory factory = new JsonFactory();
    JsonParser jsonParserPt = factory.createJsonParser(string);
    jsonParserPt.nextToken();
    MapGeometry mapGeom = GeometryEngine.jsonToGeometry(jsonParserPt);
    return OGCGeometry.createFromEsriGeometry(mapGeom.getGeometry(),
        mapGeom.getSpatialReference());
  }
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.JsonParser

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.