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


Java JsonFactory.createJsonParser方法代碼示例

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


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

示例1: readJsonEntry

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
/**
 * barファイルエントリからJSONファイルを読み込む.
 * @param <T> JSONMappedObject
 * @param inStream barファイルエントリのInputStream
 * @param entryName entryName
 * @param clazz clazz
 * @return JSONファイルから読み込んだオブジェクト
 * @throws IOException JSONファイル読み込みエラー
 */
public static <T> T readJsonEntry(
        InputStream inStream, String entryName, Class<T> clazz) throws IOException {
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    jp = f.createJsonParser(inStream);
    JsonToken token = jp.nextToken(); // JSONルート要素("{")
    Pattern formatPattern = Pattern.compile(".*/+(.*)");
    Matcher formatMatcher = formatPattern.matcher(entryName);
    String jsonName = formatMatcher.replaceAll("$1");
    T json = null;
    if (token == JsonToken.START_OBJECT) {
        try {
            json = mapper.readValue(jp, clazz);
        } catch (UnrecognizedPropertyException ex) {
            throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
        }
    } else {
        throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
    }
    return json;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:32,代碼來源:BarFileUtils.java

示例2: getRequestBody

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
/**
 * リクエストボディを解析してEventオブジェクトを取得する.
 * @param reader Http入力ストリーム
 * @return 解析したEventオブジェクト
 */
protected JSONEvent getRequestBody(final Reader reader) {
    JSONEvent event = null;
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    try {
        jp = f.createJsonParser(reader);
        JsonToken token = jp.nextToken(); // JSONルート要素("{")
        if (token == JsonToken.START_OBJECT) {
            event = mapper.readValue(jp, JSONEvent.class);
        } else {
            throw PersoniumCoreException.Event.JSON_PARSE_ERROR;
        }
    } catch (IOException e) {
        throw PersoniumCoreException.Event.JSON_PARSE_ERROR;
    }
    return event;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:24,代碼來源:EventResource.java

示例3: JsonFactory

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
/**
 * manifest.jsonのschema値がURL形式である場合trueが返卻されること.
 * @throws IOException IOException
 */
@SuppressWarnings("unchecked")
@Test
public void manifest_jsonのschema値がURL形式である場合trueが返卻されること() throws IOException {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "http://app1.example.com/");
    JsonParser jp = f.createJsonParser(json.toJSONString());
    ObjectMapper mapper = new ObjectMapper();
    jp.nextToken();

    JSONManifest manifest = mapper.readValue(jp, JSONManifest.class);

    assertTrue(manifest.checkSchema());
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:22,代碼來源:JSONManifestTest.java

示例4: JsonFactory

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
/**
 * bar_versionを指定しない場合に例外がスローされる.
 */
@Test
@SuppressWarnings({"unchecked" })
public void bar_versionを指定しない場合に例外がスローされる() {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "http://app1.example.com");

    try {
        JsonParser jp = f.createJsonParser(json.toJSONString());
        ObjectMapper mapper = new ObjectMapper();
        jp.nextToken();

        TestBarRunner testBarRunner = new TestBarRunner();
        testBarRunner.manifestJsonValidate(jp, mapper);
    } catch (PersoniumCoreException dce) {
        assertEquals(400, dce.getStatus());
        assertEquals("PR400-BI-0006", dce.getCode());
        return;
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
    fail("PersoniumCoreExceptionが返卻されない");
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:29,代碼來源:BarFileValidateTest.java

示例5: constructGeometry

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
private com.esri.core.geometry.Geometry constructGeometry(com.esri.ges.spatial.Geometry geo) throws Exception
{
	try{
		String jsonIn = geo.toJson();
		JsonFactory jf = new JsonFactory();
		JsonParser jp = jf.createJsonParser(jsonIn);
		MapGeometry mgeo = GeometryEngine.jsonToGeometry(jp);
		com.esri.core.geometry.Geometry geoIn= mgeo.getGeometry();
		return GeometryEngine.project(geoIn, srIn, srBuffer);
	}
	catch(Exception e)
	{
		LOG.error(e.getMessage());
		LOG.error(e.getStackTrace());
		throw(e);
	}
}
 
開發者ID:Esri,項目名稱:defense-solutions-proofs-of-concept,代碼行數:18,代碼來源:QueryReportProcessor.java

示例6: getSpecificJSONValue

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
private String getSpecificJSONValue(HttpResponse response, String jsonKey) throws JsonParseException, IllegalStateException, IOException {
	InputStream content = response.getEntity().getContent();
	if (isSuccessfulResponse(response)) {
		JsonFactory f = new JsonFactory();
		JsonParser jp = f.createJsonParser(content);
		while ((jp.nextToken()) != JsonToken.END_OBJECT) {
			if (jsonKey.equals(jp.getCurrentName())) {
				jp.nextToken();
				return jp.getText();
			}
		}
	} else {
		String string = IOUtils.toString(content);
		System.err.println(string);
	}
	return null;
}
 
開發者ID:ExLibrisGroup,項目名稱:Rosetta.NetAppStoragePlugin,代碼行數:18,代碼來源:CDMIConnector.java

示例7: readInternal

import org.codehaus.jackson.JsonFactory; //導入方法依賴的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

示例8: getJsonParser

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
private JsonParser getJsonParser(String from, String to, String subject, String text) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory jsonFactory = new JsonFactory(mapper);

    ObjectNode json = mapper.createObjectNode();

    if (isNotBlank(from)) {
        json.put(FROM_ADDRESS, from);
    }

    if (isNotBlank(to)) {
        json.put(TO_ADDRESS, to);
    }

    if (isNotBlank(subject)) {
        json.put(SUBJECT, subject);
    }

    if (isNotBlank(text)) {
        json.put(MESSAGE, text);
    }

    return jsonFactory.createJsonParser(json.toString());
}
 
開發者ID:motech,項目名稱:motech,代碼行數:25,代碼來源:MailDeserializerTest.java

示例9: removeZFromGeom

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
private String removeZFromGeom(String geomString)
{
	geomString = new String(geomString);
	JsonFactory factory = new JsonFactory();
	ObjectMapper mapper = new ObjectMapper(factory);
	JsonParser parser;
	try
	{
		parser = factory.createJsonParser(geomString.getBytes());
		TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { };
		HashMap<String, Object> o = mapper.readValue(parser, typeRef);
		if (o.containsKey("z"))
		{
			o.remove("z");
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			mapper.writeValue(baos, o);
			geomString = baos.toString();
		}
	}
	catch (Exception e)
	{
		throw new RuntimeException(LOGGER.translate("SERVICE_AREA_ERROR_REMOVING_Z", e.getMessage()), e);
	}
	return geomString;
}
 
開發者ID:Esri,項目名稱:service-area-calculator-for-geoevent,代碼行數:26,代碼來源:ServiceAreaCalculator.java

示例10: readServerConfigForPublicKeys

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
private static Map<Integer, File> readServerConfigForPublicKeys(File file) throws IOException {
    Map<Integer, File> publicKeyFileMap = Maps.newHashMap();

    BufferedReader reader = new BufferedReader(new FileReader(file));
    JsonFactory factory = new JsonFactory();
    JsonParser jsonParser = factory.createJsonParser(reader);
    ObjectMapper mapper = new ObjectMapper();

    JsonNode root = mapper.readTree(jsonParser);
    Iterator<JsonNode> serverIterator = root.get("servers").getElements();

    while (serverIterator.hasNext()) {
        JsonNode server = serverIterator.next();

        publicKeyFileMap.put(server.get("id").getIntValue(), new File(server.get("public_key").getTextValue()));
    }

    return publicKeyFileMap;
}
 
開發者ID:AndyMoreland,項目名稱:cs-244-project,代碼行數:20,代碼來源:PBFTServerInstanceRunner.java

示例11: test3

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
@Test
public void test3() throws JsonParseException, IOException {
	ObjectMapper mapper = new ObjectMapper();
	String json = "[{\"foo\": \"bar\"},{\"foo\": \"biz\"}]";
	
	JsonFactory f = new JsonFactory();
	JsonParser jp = f.createJsonParser(json);
	// advance stream to START_ARRAY first:
	jp.nextToken();
	// and then each time, advance to opening START_OBJECT
	while (jp.nextToken() == JsonToken.START_OBJECT) {
		Foo foobar = mapper.readValue(jp, Foo.class);
		// process
		// after binding, stream points to closing END_OBJECT
		
		System.out.println(foobar);
	}
}
 
開發者ID:liuxianqiang,項目名稱:jackson-in-five-minutes,代碼行數:19,代碼來源:StreamAPI.java

示例12: removeZFromGeom

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
private String removeZFromGeom( String geomString )
{
  geomString = new String( geomString );
  JsonFactory factory = new JsonFactory();
  ObjectMapper mapper = new ObjectMapper(factory);
  JsonParser parser;
  try
  {
    parser = factory.createJsonParser( geomString.getBytes() );
    TypeReference<HashMap<String,Object>> typeRef = new TypeReference<HashMap<String,Object>>() {};
    HashMap<String,Object> o = mapper.readValue(parser, typeRef);
    if( o.containsKey( "z" ) )
    {
      o.remove( "z" );
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      mapper.writeValue( baos, o );
      geomString = baos.toString();
    }
  }
  catch( Exception e )
  {
    throw new RuntimeException( e );
  }
  return geomString;
}
 
開發者ID:Esri,項目名稱:route-monitor-for-geoevent,代碼行數:26,代碼來源:NetworkAnalystServerConnection.java

示例13: parseJson

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
private void parseJson(InputStream inJsonStream, OutputStream outJsonStream) throws IOException {

        JsonFactory factory = new JsonFactory();
        JsonParser jsonParser = factory.createJsonParser(inJsonStream);
        jsonParser.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); //stop jasonParser.close from closing stream
        
/* use the streaming json parse approach, faster?
 */
       while (true) {
           
            try {
                parseJsonElement(jsonParser);
                processJson();
            }
            
            catch(IOException ioException){ //lost the stream probably
                //Freedomotic.logger.severe(myXbmcSystem.getXbmcHost()+" : IO Exception in parseJson"); //lost the stream probably, xbmc closed?
                throw new IOException( "lost connection or bad data");
            }
       }
    }
 
開發者ID:SteveHobbs,項目名稱:freedomotic-xbmc-old,代碼行數:22,代碼來源:XbmcThread.java

示例14: fetch

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
public JsonNode fetch() {

        InputStream jsonStream = null;

        // try to  fetch remote
        // XXX

        // fallback to local static definition
        try {
            jsonStream = this.getClass().getResource("/default-def/types.json").openStream();

            ObjectMapper mapper = new ObjectMapper();
            JsonFactory factory = new JsonFactory();
            JsonParser parser = factory.createJsonParser(jsonStream);

            return mapper.readTree(parser);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;

    }
 
開發者ID:tiry,項目名稱:nuxeo-mule-connector,代碼行數:25,代碼來源:TypeDefinitionFecther.java

示例15: getCurrentRetrainingThreshold

import org.codehaus.jackson.JsonFactory; //導入方法依賴的package包/類
private int getCurrentRetrainingThreshold() throws Exception {
	try {
		String retrainingThreshold = this.getRetainingThreshold();

		ObjectMapper mapper = JacksonWrapper.getObjectMapper();
		JsonFactory factory = mapper.getJsonFactory(); // since 2.1 use
														// mapper.getFactory()
														// instead
		JsonParser jp = factory.createJsonParser(retrainingThreshold);
		JsonNode actualObj = mapper.readTree(jp);

		JsonNode nameNode = actualObj.get("sampleCountThreshold");

		int sampleCountThreshold = Integer.parseInt(nameNode.asText());

		return sampleCountThreshold;
	} catch (Exception e) {
		logger.error("Exception while getting CurrentRetrainingThreshold", e);
		return 50;

	}
}
 
開發者ID:qcri-social,項目名稱:AIDR,代碼行數:23,代碼來源:TaggerServiceImpl.java


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