當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonParser.readValueAs方法代碼示例

本文整理匯總了Java中org.codehaus.jackson.JsonParser.readValueAs方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.readValueAs方法的具體用法?Java JsonParser.readValueAs怎麽用?Java JsonParser.readValueAs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jackson.JsonParser的用法示例。


在下文中一共展示了JsonParser.readValueAs方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readInternal

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
protected Object[] readInternal(Class<?>[] parameterTypes, String payload) throws Exception {
	JsonFactory jsonFactory = this.objectMapper.getJsonFactory();
	JsonParser jp = jsonFactory.createJsonParser(payload);
	JsonToken token;
	List<Object> lObjs = new ArrayList<Object>();
	int i=0;
	while ((token = jp.nextToken()) != null) {
	    switch (token) {
	    	case VALUE_NUMBER_INT:
               case VALUE_STRING:
	        case START_OBJECT:
	        	Object obj = jp.readValueAs(parameterTypes[i]);
	        	lObjs.add(obj);
			    i++;
	            break;
		default:
			break;
	    }
	}
	if( lObjs.size() != parameterTypes.length) {
		throw new Exception("Parsed parameters do not match requested types.");
	}
	Object [] parametersFound = lObjs.toArray();
	return parametersFound;
}
 
開發者ID:Appverse,項目名稱:appverse-server,代碼行數:26,代碼來源:CustomMappingJacksonHttpMessageConverter.java

示例2: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public Variable<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
	String fieldName;
	Object value;

	// parser
	{
		jp.nextToken();
		fieldName = jp.getCurrentName();
		jp.nextToken();
		Class<?> type = Variable.Names.Registry.type(fieldName);
		value = jp.readValueAs(type);
		jp.nextToken();
	}

	return Variable.Builder.value(fieldName, value);
}
 
開發者ID:testobject,項目名稱:visual-scripting,代碼行數:18,代碼來源:Store.java

示例3: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public CloudResources deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
        JsonProcessingException {
    TypeReference<List<CloudResource>> ref = new TypeReference<List<CloudResource>>() {
    };
    return new CloudResources((Collection<? extends CloudResource>) jp.readValueAs(ref));
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:9,代碼來源:CloudResources.java

示例4: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public Set<String> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
		JsonProcessingException {
	JsonToken token = jp.getCurrentToken();
	if (token.isScalarValue()) {
		String list = jp.getText();
		list = list.replaceAll("\\s+", ",");
		return new LinkedHashSet<String>(Arrays.asList(StringUtils.commaDelimitedListToStringArray(list)));
	}
	return jp.readValueAs(new TypeReference<Set<String>>() {
	});
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:13,代碼來源:BaseClientDetails.java

示例5: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public Logs deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    return new Logs(jp.readValueAs(Object.class));
}
 
開發者ID:Aptoide,項目名稱:AppCoins-ethereumj,代碼行數:5,代碼來源:Logs.java

示例6: testStreamingJSON

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Test
public void testStreamingJSON() throws Exception {
  // Test scanning particular columns with limit.
  StringBuilder builder = new StringBuilder();
  builder.append("/*");
  builder.append("?");
  builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
  builder.append("&");
  builder.append(Constants.SCAN_LIMIT + "=20");
  Response response = client.get("/" + TABLE + builder.toString(),
    Constants.MIMETYPE_JSON);
  assertEquals(200, response.getCode());
  assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
  ObjectMapper mapper = new JacksonProvider()
      .locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
  CellSetModel model = mapper.readValue(response.getStream(), CellSetModel.class);
  int count = TestScannerResource.countCellSet(model);
  assertEquals(20, count);
  checkRowsNotNull(model);

  //Test scanning with no limit.
  builder = new StringBuilder();
  builder.append("/*");
  builder.append("?");
  builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_2);
  response = client.get("/" + TABLE + builder.toString(),
    Constants.MIMETYPE_JSON);
  assertEquals(200, response.getCode());
  assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
  model = mapper.readValue(response.getStream(), CellSetModel.class);
  count = TestScannerResource.countCellSet(model);
  assertEquals(expectedRows2, count);
  checkRowsNotNull(model);

  //Test with start row and end row.
  builder = new StringBuilder();
  builder.append("/*");
  builder.append("?");
  builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
  builder.append("&");
  builder.append(Constants.SCAN_START_ROW + "=aaa");
  builder.append("&");
  builder.append(Constants.SCAN_END_ROW + "=aay");
  response = client.get("/" + TABLE + builder.toString(),
    Constants.MIMETYPE_JSON);
  assertEquals(200, response.getCode());

  count = 0;
  JsonFactory jfactory = new JsonFactory(mapper);
  JsonParser jParser = jfactory.createJsonParser(response.getStream());
  boolean found = false;
  while (jParser.nextToken() != JsonToken.END_OBJECT) {
    if(jParser.getCurrentToken() == JsonToken.START_OBJECT && found) {
      RowModel row = jParser.readValueAs(RowModel.class);
      assertNotNull(row.getKey());
      for (int i = 0; i < row.getCells().size(); i++) {
        if (count == 0) {
          assertEquals("aaa", Bytes.toString(row.getKey()));
        }
        if (count == 23) {
          assertEquals("aax", Bytes.toString(row.getKey()));
        }
        count++;
      }
      jParser.skipChildren();
    } else {
      found = jParser.getCurrentToken() == JsonToken.START_ARRAY;
    }
  }
  assertEquals(24, count);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:72,代碼來源:TestTableScan.java

示例7: importSorted

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
        IPartitioner partitioner) throws IOException
{
    int importedKeys = 0; // already imported keys count
    long start = System.nanoTime();

    JsonParser parser = getParser(jsonFile);

    if (keyCountToImport == null)
    {
        keyCountToImport = 0;
        System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");

        parser.nextToken(); // START_ARRAY
        while (parser.nextToken() != null)
        {
            parser.skipChildren();
            if (parser.getCurrentToken() == JsonToken.END_ARRAY)
                break;

            keyCountToImport++;
        }
    }

    System.out.printf("Importing %s keys...%n", keyCountToImport);

    parser = getParser(jsonFile); // renewing parser
    SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport, ActiveRepairService.UNREPAIRED_SSTABLE);

    int lineNumber = 1;
    DecoratedKey prevStoredKey = null;

    parser.nextToken(); // START_ARRAY
    while (parser.nextToken() != null)
    {
        String key = parser.getCurrentName();
        Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
        DecoratedKey currentKey = partitioner.decorateKey(getKeyValidator(columnFamily).fromString((String) row.get("key")));

        if (row.containsKey("metadata"))
            parseMeta((Map<?, ?>) row.get("metadata"), columnFamily, null);

        addColumnsToCF((List<?>) row.get("cells"), columnFamily);

        if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
        {
            System.err
                    .printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
                            lineNumber, key);
            return -1;
        }

        // saving decorated key
        writer.append(currentKey, columnFamily);
        columnFamily.clear();

        prevStoredKey = currentKey;
        importedKeys++;
        lineNumber++;

        long current = System.nanoTime();

        if (TimeUnit.NANOSECONDS.toSeconds(current - start) >= 5) // 5 secs.
        {
            System.out.printf("Currently imported %d keys.%n", importedKeys);
            start = current;
        }

        if (keyCountToImport == importedKeys)
            break;

    }

    writer.closeAndOpenReader();

    return importedKeys;
}
 
開發者ID:vcostet,項目名稱:cassandra-kmean,代碼行數:78,代碼來源:SSTableImport.java

示例8: importSorted

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
        IPartitioner<?> partitioner) throws IOException
{
    int importedKeys = 0; // already imported keys count
    long start = System.nanoTime();

    JsonParser parser = getParser(jsonFile);

    if (keyCountToImport == null)
    {
        keyCountToImport = 0;
        System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");

        parser.nextToken(); // START_ARRAY
        while (parser.nextToken() != null)
        {
            parser.skipChildren();
            if (parser.getCurrentToken() == JsonToken.END_ARRAY)
                break;

            keyCountToImport++;
        }
    }

    System.out.printf("Importing %s keys...%n", keyCountToImport);

    parser = getParser(jsonFile); // renewing parser
    SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport);

    int lineNumber = 1;
    DecoratedKey prevStoredKey = null;

    parser.nextToken(); // START_ARRAY
    while (parser.nextToken() != null)
    {
        String key = parser.getCurrentName();
        Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
        DecoratedKey currentKey = partitioner.decorateKey(hexToBytes((String) row.get("key")));

        if (row.containsKey("metadata"))
            parseMeta((Map<?, ?>) row.get("metadata"), columnFamily, null);

        if (columnFamily.getType() == ColumnFamilyType.Super && oldSCFormat)
            addToSuperCF((Map<?, ?>)row.get("columns"), columnFamily);
        else
            addToStandardCF((List<?>)row.get("columns"), columnFamily);

        if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
        {
            System.err
                    .printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
                            lineNumber, key);
            return -1;
        }

        // saving decorated key
        writer.append(currentKey, columnFamily);
        columnFamily.clear();

        prevStoredKey = currentKey;
        importedKeys++;
        lineNumber++;

        long current = System.nanoTime();

        if (TimeUnit.NANOSECONDS.toSeconds(current - start) >= 5) // 5 secs.
        {
            System.out.printf("Currently imported %d keys.%n", importedKeys);
            start = current;
        }

        if (keyCountToImport == importedKeys)
            break;

    }

    writer.closeAndOpenReader();

    return importedKeys;
}
 
開發者ID:pgaref,項目名稱:ACaZoo,代碼行數:81,代碼來源:SSTableImport.java

示例9: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public Shape deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    String shape = jp.readValueAs(String.class);

    return Shape.valueOf(shape.toUpperCase());
}
 
開發者ID:JonathanGeoffroy,項目名稱:LifeMonitor,代碼行數:7,代碼來源:ShapeDeserializer.java

示例10: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public HowToTake deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    String howToTake = jp.readValueAs(String.class);
    return HowToTake.valueOf(howToTake.toUpperCase());
}
 
開發者ID:JonathanGeoffroy,項目名稱:LifeMonitor,代碼行數:6,代碼來源:HowToTakeDeserializer.java

示例11: importSorted

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
        IPartitioner<?> partitioner) throws IOException
{
    int importedKeys = 0; // already imported keys count
    long start = System.nanoTime();

    JsonParser parser = getParser(jsonFile);

    if (keyCountToImport == null)
    {
        keyCountToImport = 0;
        System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");

        parser.nextToken(); // START_ARRAY
        while (parser.nextToken() != null)
        {
            parser.skipChildren();
            if (parser.getCurrentToken() == JsonToken.END_ARRAY)
                break;

            keyCountToImport++;
        }
    }

    System.out.printf("Importing %s keys...%n", keyCountToImport);

    parser = getParser(jsonFile); // renewing parser
    SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport, ActiveRepairService.UNREPAIRED_SSTABLE);

    int lineNumber = 1;
    DecoratedKey prevStoredKey = null;

    parser.nextToken(); // START_ARRAY
    while (parser.nextToken() != null)
    {
        String key = parser.getCurrentName();
        Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
        DecoratedKey currentKey = partitioner.decorateKey(getKeyValidator(columnFamily).fromString((String) row.get("key")));

        if (row.containsKey("metadata"))
            parseMeta((Map<?, ?>) row.get("metadata"), columnFamily, null);

        addColumnsToCF((List<?>) row.get("cells"), columnFamily);

        if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
        {
            System.err
                    .printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
                            lineNumber, key);
            return -1;
        }

        // saving decorated key
        writer.append(currentKey, columnFamily);
        columnFamily.clear();

        prevStoredKey = currentKey;
        importedKeys++;
        lineNumber++;

        long current = System.nanoTime();

        if (TimeUnit.NANOSECONDS.toSeconds(current - start) >= 5) // 5 secs.
        {
            System.out.printf("Currently imported %d keys.%n", importedKeys);
            start = current;
        }

        if (keyCountToImport == importedKeys)
            break;

    }

    writer.closeAndOpenReader();

    return importedKeys;
}
 
開發者ID:daidong,項目名稱:GraphTrek,代碼行數:78,代碼來源:SSTableImport.java

示例12: importSorted

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
        IPartitioner<?> partitioner) throws IOException
{
    int importedKeys = 0; // already imported keys count
    long start = System.currentTimeMillis();

    JsonParser parser = getParser(jsonFile);

    if (keyCountToImport == null)
    {
        keyCountToImport = 0;
        System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");

        parser.nextToken(); // START_ARRAY
        while (parser.nextToken() != null)
        {
            parser.skipChildren();
            if (parser.getCurrentToken() == JsonToken.END_ARRAY)
                break;

            keyCountToImport++;
        }
    }

    System.out.printf("Importing %s keys...%n", keyCountToImport);

    parser = getParser(jsonFile); // renewing parser
    SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport);

    int lineNumber = 1;
    DecoratedKey prevStoredKey = null;

    parser.nextToken(); // START_ARRAY
    while (parser.nextToken() != null)
    {
        String key = parser.getCurrentName();
        Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
        DecoratedKey currentKey = partitioner.decorateKey(hexToBytes((String) row.get("key")));

        if (row.containsKey("metadata"))
            parseMeta((Map<?, ?>) row.get("metadata"), columnFamily);


        if (columnFamily.getType() == ColumnFamilyType.Super)
            addToSuperCF((Map<?, ?>)row.get("columns"), columnFamily);
        else
            addToStandardCF((List<?>)row.get("columns"), columnFamily);

        if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
        {
            System.err
                    .printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
                            lineNumber, key);
            return -1;
        }

        // saving decorated key
        writer.append(currentKey, columnFamily);
        columnFamily.clear();

        prevStoredKey = currentKey;
        importedKeys++;
        lineNumber++;

        long current = System.currentTimeMillis();

        if (current - start >= 5000) // 5 secs.
        {
            System.out.printf("Currently imported %d keys.%n", importedKeys);
            start = current;
        }

        if (keyCountToImport == importedKeys)
            break;

    }

    writer.closeAndOpenReader();

    return importedKeys;
}
 
開發者ID:dprguiuc,項目名稱:Cassandra-Wasef,代碼行數:82,代碼來源:SSTableImport.java

示例13: importSorted

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
        IPartitioner<?> partitioner) throws IOException
{
    int importedKeys = 0; // already imported keys count
    long start = System.nanoTime();

    JsonParser parser = getParser(jsonFile);

    if (keyCountToImport == null)
    {
        keyCountToImport = 0;
        System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");

        parser.nextToken(); // START_ARRAY
        while (parser.nextToken() != null)
        {
            parser.skipChildren();
            if (parser.getCurrentToken() == JsonToken.END_ARRAY)
                break;

            keyCountToImport++;
        }
    }

    System.out.printf("Importing %s keys...%n", keyCountToImport);

    parser = getParser(jsonFile); // renewing parser
    SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport, ActiveRepairService.UNREPAIRED_SSTABLE);

    int lineNumber = 1;
    DecoratedKey prevStoredKey = null;

    parser.nextToken(); // START_ARRAY
    while (parser.nextToken() != null)
    {
        String key = parser.getCurrentName();
        Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
        DecoratedKey currentKey = partitioner.decorateKey(hexToBytes((String) row.get("key")));

        if (row.containsKey("metadata"))
            parseMeta((Map<?, ?>) row.get("metadata"), columnFamily, null);

        if (columnFamily.getType() == ColumnFamilyType.Super && oldSCFormat)
            addToSuperCF((Map<?, ?>)row.get("columns"), columnFamily);
        else
            addToStandardCF((List<?>)row.get("columns"), columnFamily);

        if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
        {
            System.err
                    .printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
                            lineNumber, key);
            return -1;
        }

        // saving decorated key
        writer.append(currentKey, columnFamily);
        columnFamily.clear();

        prevStoredKey = currentKey;
        importedKeys++;
        lineNumber++;

        long current = System.nanoTime();

        if (TimeUnit.NANOSECONDS.toSeconds(current - start) >= 5) // 5 secs.
        {
            System.out.printf("Currently imported %d keys.%n", importedKeys);
            start = current;
        }

        if (keyCountToImport == importedKeys)
            break;

    }

    writer.closeAndOpenReader();

    return importedKeys;
}
 
開發者ID:rajath26,項目名稱:cassandra-trunk,代碼行數:81,代碼來源:SSTableImport.java

示例14: deserialize

import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
/**
 * Method that can be called to ask implementation to deserialize
 * JSON content into the value type this serializer handles.
 * Returned instance is to be constructed by method itself.
 * <p/>
 * Pre-condition for this method is that the parser points to the
 * first event that is part of value to deserializer (and which
 * is never JSON 'null' literal, more on this below): for simple
 * types it may be the only value; and for structured types the
 * Object start marker.
 * Post-condition is that the parser will point to the last
 * event that is part of deserialized value (or in case deserialization
 * fails, event that was not recognized or usable, which may be
 * the same event as the one it pointed to upon call).
 * <p/>
 * Note that this method is never called for JSON null literal,
 * and thus deserializers need (and should) not check for it.
 *
 * @param jp   Parsed used for reading JSON content
 * @param ctxt Context that can be used to access information about
 *             this deserialization activity.
 * @return Deserializer value
 */
@Override
public ErrorResponse deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
    JsonNode node = jp.readValueAs(JsonNode.class);
    if(node.isObject()){
        if(node.has("error")){
            JsonNode error = node.get("error");
            return (ErrorResponse) mapper.reader(ErrorResponse.class).readValue(error);
        }
    }
    return null;
}
 
開發者ID:jlinn,項目名稱:stripe-api-java,代碼行數:38,代碼來源:ErrorDeserializer.java


注:本文中的org.codehaus.jackson.JsonParser.readValueAs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。