本文整理匯總了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;
}
示例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;
}
示例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());
}
示例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が返卻されない");
}
示例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);
}
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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");
}
}
}
示例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;
}
示例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;
}
}