Package org.codehaus.jackson

Examples of org.codehaus.jackson.JsonParser


    final V2LiteMediaJSON pbJSON = new V2LiteMediaJSON();

    public MediaContent deserialize(byte[] array) throws Exception
    {
        V2LiteMedia.MediaContent.Builder builder = V2LiteMedia.MediaContent.newBuilder();
        JsonParser parser = pbJSON.getJsonFactory().createJsonParser(array);
        pbJSON.mergeFrom(parser, builder);
        parser.close();
        return builder.build();
    }
View Full Code Here


    final V2SpeedMediaNumericJSON pbJSON = new V2SpeedMediaNumericJSON();

    public MediaContent deserialize(byte[] array) throws Exception
    {
        V2SpeedMedia.MediaContent.Builder builder = V2SpeedMedia.MediaContent.newBuilder();
        JsonParser parser = pbJSON.getJsonFactory().createJsonParser(array);
        pbJSON.mergeFrom(parser, builder);
        parser.close();
        return builder.build();
    }
View Full Code Here

    final V2LiteMediaNumericJSON pbJSON = new V2LiteMediaNumericJSON();

    public MediaContent deserialize(byte[] array) throws Exception
    {
        V2LiteMedia.MediaContent.Builder builder = V2LiteMedia.MediaContent.newBuilder();
        JsonParser parser = pbJSON.getJsonFactory().createJsonParser(array);
        pbJSON.mergeFrom(parser, builder);
        parser.close();
        return builder.build();
    }
View Full Code Here

    final ReflectionJSON pbJSON = new ReflectionJSON(new Class[]{V2LiteMedia.class});

    public MediaContent deserialize(byte[] array) throws Exception
    {
        V2LiteMedia.MediaContent.Builder builder = V2LiteMedia.MediaContent.newBuilder();
        JsonParser parser = pbJSON.getJsonFactory().createJsonParser(array);
        pbJSON.mergeFrom(parser, builder);
        parser.close();
        return builder.build();
    }
View Full Code Here

        try {
            if ((rootName == null || "".equals(rootName)) && (configuration.isRootUnwrapping())) {
                rootName = "rootElement";
            }
           
            final JsonParser rawParser = new JsonFactory().createJsonParser(reader);
            final JsonParser nonListParser = configuration.isRootUnwrapping() ? JacksonRootAddingParser.createRootAddingParser
                    (rawParser, rootName) : rawParser;

            XmlEventProvider eventStack = null;
            switch (configuration.getNotation()) {
                case MAPPED:
View Full Code Here

        _testJsonExpr("[\"one\",2,\"3\"]");
    }

    public void _testJsonExpr(String expr) throws Exception {
        JsonFactory factory = new JsonFactory();
        JsonParser p = factory.createJsonParser(expr);
        JsonParser rap = JacksonRootAddingParser.createRootAddingParser(p, "root");
        StringWriter sw = new StringWriter();
        JsonGenerator g = factory.createJsonGenerator(sw);
        rap.nextToken();
        while (rap.hasCurrentToken()) {
            g.copyCurrentEvent(rap);
            rap.nextToken();
        }
        g.flush();
        System.out.println(sw);
        assertEquals("{\"root\":" + expr + "}", sw.toString());
    }
View Full Code Here

     */
    public void testSimpleOffsets() throws IOException
    {
        byte[] data = _smileDoc("[ true, null, false, 511 ]", true); // true -> write header
       
        JsonParser p = _smileParser(data);
        assertNull(p.getCurrentToken());
        JsonLocation loc = p.getCurrentLocation();
        assertNotNull(loc);
        // first: -1 for "not known", for character-based stuff
        assertEquals(-1, loc.getCharOffset());
        // except that with 1.9.7 and above, we also consider column to be same as offset, for convenience
        assertEquals(4, loc.getColumnNr());
        assertEquals(-1, loc.getLineNr());
        // but first 4 bytes are for header
        assertEquals(4, loc.getByteOffset());

        // array marker is a single byte, so:
        assertToken(JsonToken.START_ARRAY, p.nextToken());
        assertEquals(5, p.getCurrentLocation().getByteOffset());
        assertEquals(4, p.getTokenLocation().getByteOffset());

        // same for true and others except for last int
        assertToken(JsonToken.VALUE_TRUE, p.nextToken());
        assertEquals(6, p.getCurrentLocation().getByteOffset());
        assertEquals(5, p.getTokenLocation().getByteOffset());

        assertToken(JsonToken.VALUE_NULL, p.nextToken());
        assertEquals(7, p.getCurrentLocation().getByteOffset());
        assertEquals(6, p.getTokenLocation().getByteOffset());

        assertToken(JsonToken.VALUE_FALSE, p.nextToken());
        assertEquals(8, p.getCurrentLocation().getByteOffset());
        assertEquals(7, p.getTokenLocation().getByteOffset());

        // 0x1FF takes 3 bytes (type byte, 7/6 bit segments)
        assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
        assertEquals(511, p.getIntValue());
        assertEquals(11, p.getCurrentLocation().getByteOffset());
        assertEquals(8, p.getTokenLocation().getByteOffset());
       
        assertToken(JsonToken.END_ARRAY, p.nextToken());
        assertEquals(12, p.getCurrentLocation().getByteOffset());
        assertEquals(11, p.getTokenLocation().getByteOffset());

        assertNull(p.nextToken());
        p.close();
    }
View Full Code Here

    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

    if (ApitraryOrmConfiguration.showJson()) {
      showJson(json);
    }

    JsonFactory f = new JsonFactory();
    JsonParser jp = f.createJsonParser(json);

    JsonToken token = jp.nextToken();
    String fieldName = jp.getCurrentName();
    while (!(token == null && fieldName == null)) {
      on(token, fieldName, jp);

      token = jp.nextToken();
      fieldName = jp.getCurrentName();
    }
  }
View Full Code Here

    try {
      JsonFactory jsonFactory = new JsonFactory();
      ObjectMapper objectMapper = new ObjectMapper();
      StringWriter stringWriter = new StringWriter();

      JsonParser jsonParser = jsonFactory.createJsonParser(new StringReader(json));
      JsonNode jsonNode = objectMapper.readTree(jsonParser);
      JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(stringWriter);
      jsonGenerator.useDefaultPrettyPrinter();

      objectMapper.writeTree(jsonGenerator, jsonNode);
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.