Package com.fasterxml.jackson.core

Examples of com.fasterxml.jackson.core.JsonParser


     */
    public AbsoluteRange getHistogramBoundaries() {
        if (boundaries == null) {
            try {
                ObjectMapper mapper = new ObjectMapper();
                JsonParser jp = mapper.getFactory().createParser(getBuiltQuery());
                JsonNode rootNode = mapper.readTree(jp);
                JsonNode timestampNode = rootNode.findValue("range").findValue("timestamp");
                String from = Tools.elasticSearchTimeFormatToISO8601(timestampNode.findValue("from").asText());
                String to = Tools.elasticSearchTimeFormatToISO8601(timestampNode.findValue("to").asText());
                boundaries = new AbsoluteRange(from, to);
View Full Code Here


      JsonMappingException {
    // Read mapping out of JSON file
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory factory = new JsonFactory();
    InputStream is = this.getClass().getResourceAsStream(MAPPING_FILE);
    JsonParser jp = factory.createParser(is);

    jp.nextToken();
    mappings.clear();
    while (jp.nextToken() == JsonToken.START_OBJECT) {
      URLMapping mapping = mapper.readValue(jp, URLMapping.class);
      mappings.add(mapping);
    }
  }
View Full Code Here

   * @return the decoded structure.
   */
  @Override
  public final CouchbaseStorable decode(final Object source, final CouchbaseStorable target) {
    try {
      JsonParser parser = factory.createParser((String) source);
      while (parser.nextToken() != null) {
        JsonToken currentToken = parser.getCurrentToken();

        if (currentToken == JsonToken.START_OBJECT) {
          return decodeObject(parser, (CouchbaseDocument) target);
        } else if (currentToken == JsonToken.START_ARRAY) {
          return decodeArray(parser, new CouchbaseList());
        } else {
          throw new MappingException("JSON to decode needs to start as array or object!");
        }
      }
      parser.close();
    } catch (IOException ex) {
      throw new RuntimeException("Could not decode JSON", ex);
    }
    return target;
  }
View Full Code Here

            // Check if it is a "RealFilter"
            JsonNode queryParam = root.get("queryParam");
            if ( queryParam != null && queryParam.isValueNode() ) {

                // pass in our objectCodec so that the subJsonParser knows about our configured Modules and Annotations
                JsonParser subJsonParser = root.traverse( objectCodec );

                return subJsonParser.readValueAs( RealFilter.class );
            }

            // We assume it is a LogicalFilter
            Iterator<String> iter = root.fieldNames();
            String key = iter.next();

            JsonNode arrayNode = root.iterator().next();
            if ( arrayNode == null || arrayNode.isMissingNode() || ! arrayNode.isArray() ) {
                throw new RuntimeException( "Invalid format of LogicalFilter encountered." );
            }

            // pass in our objectCodec so that the subJsonParser knows about our configured Modules and Annotations
            JsonParser subJsonParser = arrayNode.traverse( objectCodec );
            List<QueryFilter> childrenQueryFilters = subJsonParser.readValueAs( new TypeReference<List<QueryFilter>>() {} );

            return new LogicalFilter2( QueryParam.valueOf( key ), childrenQueryFilters );
        }
View Full Code Here

        throw new UnsupportedOperationException();
    }


    public void parse(InputSource input) throws IOException, SAXException {
        JsonParser jsonParser = new JsonFactory().createParser(input.getCharacterStream());
        new JsonSaxAdapter(jsonParser, contentHandler, namespaceUri, addTypeAttributes, artificialRootName, elementNameConverter).parse();
    }
View Full Code Here

   
    JsonFactory factory = new JsonFactory();
   
    String jsonInput = "{\"name\":\"rob\",\"age\":12}";

    JsonParser jsonParser = factory.createParser(jsonInput);

    Object result = EJson.parse(jsonParser);
   
    Assert.assertTrue(result instanceof Map);
    Map<?,?> map = (Map<?,?>)result;
View Full Code Here

    JsonFactory factory = new JsonFactory();

    String jsonInput = "{\"name\":\"rob\",\"age\":12}";

    JsonParser jsonParser = factory.createParser(jsonInput);

    Object result = EJson.parseObject(jsonParser);

    Assert.assertTrue(result instanceof Map);
    Map<?,?> map = (Map<?,?>)result;
View Full Code Here

  public void test_list_jsonParser() throws IOException {

    String jsonInput = "[\"name\",\"rob\",12,13]";

    JsonFactory jsonFactory = new JsonFactory();
    JsonParser parser = jsonFactory.createParser(jsonInput);

    List<Object> list = EJson.parseList(parser);

    Assert.assertEquals(4, list.size());
    Assert.assertEquals("name", list.get(0));
View Full Code Here

    assertEquals(12L, map.get("age"));

  }

  private Map<String,Object> parseHstore(String json) throws IOException {
    JsonParser parser = jsonFactory.createParser(json);
    // BeanProperty reads the first token checking for null so
    // simulate that here
    JsonToken token = parser.nextToken();
    assertEquals(JsonToken.START_OBJECT, token);
    return (Map<String,Object>)hstore.jsonRead(parser, token);
  }
View Full Code Here

   
    BeanDescriptor<Customer> descriptor = server.getBeanDescriptor(Customer.class);
   
   
    StringReader reader = new StringReader("{\"id\":123,\"name\":\"Hello rob\"}");
    JsonParser parser = server.json().createParser(reader);
   
    Customer customer = (Customer)descriptor.jsonRead(parser, null);
   
    Assert.assertEquals(Integer.valueOf(123), customer.getId());
    Assert.assertEquals("Hello rob", customer.getName());
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.core.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.