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


Java JsonParser類代碼示例

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


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

示例1: deserialize

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@Override
public Directive deserialize(JsonParser jp, DeserializationContext ctx)
        throws IOException {
    ObjectReader reader = ObjectMapperUtil.instance().getObjectReader();
    ObjectNode obj = (ObjectNode) reader.readTree(jp);
    Iterator<Map.Entry<String, JsonNode>> elementsIterator = obj.getFields();

    String rawMessage = obj.toString();
    DialogRequestIdHeader header = null;
    JsonNode payloadNode = null;
    ObjectReader headerReader =
            ObjectMapperUtil.instance().getObjectReader(DialogRequestIdHeader.class);
    while (elementsIterator.hasNext()) {
        Map.Entry<String, JsonNode> element = elementsIterator.next();
        if (element.getKey().equals("header")) {
            header = headerReader.readValue(element.getValue());
        }
        if (element.getKey().equals("payload")) {
            payloadNode = element.getValue();
        }
    }
    if (header == null) {
        throw ctx.mappingException("Missing header");
    }
    if (payloadNode == null) {
        throw ctx.mappingException("Missing payload");
    }

    return createDirective(header, payloadNode, rawMessage);
}
 
開發者ID:dueros,項目名稱:dcs-sdk-java,代碼行數:31,代碼來源:Directive.java

示例2: deserialize

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@Override
public Window deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    
    Double value = node.get("value").asDouble();
    Window window = new Window(value);
    
    if (node.has("bounds")) {
        long lowerBound = node.get("bounds").get(0).asLong();
        long upperBound = node.get("bounds").get(1).asLong();
        
        window.withLowerBound(lowerBound).withUpperBound(upperBound);
    }

    return window;
}
 
開發者ID:PyroclastIO,項目名稱:pyroclast-java,代碼行數:17,代碼來源:WindowDeserializer.java

示例3: parseContent

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private <T> T parseContent(InputStream content, String string) {
    Map<String, Object> map = Collections.emptyMap();

    try {
        // create parser manually to lower Jackson requirements
        JsonParser jsonParser = mapper.getJsonFactory().createJsonParser(content);
        try {
            map = mapper.readValue(jsonParser, Map.class);
        } finally {
            countStreamStats(content);
        }
    } catch (IOException ex) {
        throw new EsHadoopParsingException(ex);
    }

    return (T) (string != null ? map.get(string) : map);
}
 
開發者ID:xushjie1987,項目名稱:es-hadoop-v2.2.0,代碼行數:19,代碼來源:RestClient.java

示例4: read

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
private void read(DataInput in) throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  mapper.configure(
      DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
  
  // define a module
  SimpleModule module = new SimpleModule("State Serializer",  
      new Version(0, 1, 1, "FINAL"));
  // add the state deserializer
  module.addDeserializer(StatePair.class, new StateDeserializer());

  // register the module with the object-mapper
  mapper.registerModule(module);

  JsonParser parser = 
    mapper.getJsonFactory().createJsonParser((DataInputStream)in);
  StatePool statePool = mapper.readValue(parser, StatePool.class);
  this.setStates(statePool.getStates());
  parser.close();
}
 
開發者ID:Nextzero,項目名稱:hadoop-2.6.0-cdh5.4.3,代碼行數:21,代碼來源:StatePool.java

示例5: buildScoreRule

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
private void buildScoreRule(JsonParser jsonParser,JsonNode ruleNode,ScoreRule rule){
	rule.setScoringBean(JsonUtils.getJsonValue(ruleNode, "scoringBean"));
	AssignTargetType assignTargetType=AssignTargetType.valueOf(JsonUtils.getJsonValue(ruleNode, "assignTargetType"));
	rule.setAssignTargetType(assignTargetType);
	rule.setVariableCategory(JsonUtils.getJsonValue(ruleNode, "variableCategory"));
	rule.setVariableName(JsonUtils.getJsonValue(ruleNode, "variableName"));
	rule.setVariableLabel(JsonUtils.getJsonValue(ruleNode, "variableLabel"));
	String datatypeStr=JsonUtils.getJsonValue(ruleNode, "datatype");
	if(StringUtils.isNotBlank(datatypeStr)){
		rule.setDatatype(Datatype.valueOf(datatypeStr));
	}
	try{
		JsonNode knowledgePackageWrapperNode=ruleNode.get("knowledgePackageWrapper");
		ObjectMapper mapper = (ObjectMapper)jsonParser.getCodec();
		KnowledgePackageWrapper wrapper=mapper.readValue(knowledgePackageWrapperNode, KnowledgePackageWrapper.class);
		wrapper.buildDeserialize();
		rule.setKnowledgePackageWrapper(wrapper);			
	}catch(Exception ex){
		throw new RuleException(ex);
	}
	
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:23,代碼來源:AbstractJsonDeserializer.java

示例6: configureFeature

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
private void configureFeature(Object feature, boolean enabled) {
	if (feature instanceof JsonParser.Feature) {
		this.objectMapper.configure((JsonParser.Feature) feature, enabled);
	}
	else if (feature instanceof JsonGenerator.Feature) {
		this.objectMapper.configure((JsonGenerator.Feature) feature, enabled);
	}
	else if (feature instanceof SerializationConfig.Feature) {
		this.objectMapper.configure((SerializationConfig.Feature) feature, enabled);
	}
	else if (feature instanceof DeserializationConfig.Feature) {
		this.objectMapper.configure((DeserializationConfig.Feature) feature, enabled);
	}
	else {
		throw new IllegalArgumentException("Unknown feature class: " + feature.getClass().getName());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:JacksonObjectMapperFactoryBean.java

示例7: deserialize

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@Override
public StatePair deserialize(JsonParser parser, 
                             DeserializationContext context)
throws IOException, JsonProcessingException {
  ObjectMapper mapper = (ObjectMapper) parser.getCodec();
  // set the state-pair object tree
  ObjectNode statePairObject = (ObjectNode) mapper.readTree(parser);
  Class<?> stateClass = null;
  
  try {
    stateClass = 
      Class.forName(statePairObject.get("className").getTextValue().trim());
  } catch (ClassNotFoundException cnfe) {
    throw new RuntimeException("Invalid classname!", cnfe);
  }
  
  String stateJsonString = statePairObject.get("state").toString();
  State state = (State) mapper.readValue(stateJsonString, stateClass);
  
  return new StatePair(state);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:StateDeserializer.java

示例8: deserialize

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@Override
public ProducedEventsResult deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    
    if (node.isArray()) {
        List<ProducedEventResult> responses = new ArrayList<>();
        Iterator<JsonNode> it = node.iterator();
        
        while (it.hasNext()) {
            JsonNode n = it.next();
            responses.add(new ProducedEventResult(n.get("created").asBoolean()));
        }
        
        return new ProducedEventsResult(responses);
    } else {
        String reason = node.get("reason").asText();
        return new ProducedEventsResult(reason);
    }
}
 
開發者ID:PyroclastIO,項目名稱:pyroclast-java,代碼行數:20,代碼來源:ProducedEventsResponseDeserializer.java

示例9: deserialize

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@Override
public TopicRecord deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    
    String topic = node.get("topic").asText();
    long partition = node.get("partition").asLong();
    long offset = node.get("offset").asLong();
    long timestamp = node.get("timestamp").asLong();
    
    String key = null;
    if (node.has("key")) {
        key = node.get("key").asText();
    }
    
    Map<Object, Object> value = new ObjectMapper().readValue(node.get("value").toString(), Map.class);
    return new TopicRecord(topic, key, partition, offset, timestamp, value);
}
 
開發者ID:PyroclastIO,項目名稱:pyroclast-java,代碼行數:18,代碼來源:TopicRecordDeserializer.java

示例10: deserialize

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@Override
public SubscribeToTopicResult deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    boolean success = false;
    String reason = null;
    
    if (node.has("subscribed")) {
        success = node.get("subscribed").asBoolean();
    }
    
    if (node.has("reason")) {
        reason = node.get("reason").asText();
    }

    return new SubscribeToTopicResult(success, reason);
}
 
開發者ID:PyroclastIO,項目名稱:pyroclast-java,代碼行數:17,代碼來源:SubscribeToTopicResponseDeserializer.java

示例11: deserialize

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@Override
public JsonUpdateWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

    final ObjectCodec obj = jp.getCodec();
    final JsonNode node = obj.readTree(jp).get(0);

    final Set<String> groupIds = deserializeGroupIdentifiers(node);
    return new JsonUpdateWebServer(node.get("webserverId").getValueAsText(),
                                   node.get("webserverName").getTextValue(),
                                   node.get("hostName").getTextValue(),
                                   node.get("portNumber").getValueAsText(),
                                   node.get("httpsPort").getValueAsText(),
                                   groupIds,
                                   node.get("statusPath").getTextValue(),
                                   node.get("apacheHttpdMediaId").getTextValue());
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:18,代碼來源:JsonUpdateWebServer.java

示例12: deserialize

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
@Override
public JsonCreateWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

    final ObjectCodec obj = jp.getCodec();
    final JsonNode node = obj.readTree(jp).get(0);

    final JsonNode apacheHttpdMediaId = node.get("apacheHttpdMediaId");
    final JsonCreateWebServer jcws = new JsonCreateWebServer(node.get("webserverName").getTextValue(),
            node.get("hostName").getTextValue(),
            node.get("portNumber").asText(),
            node.get("httpsPort").asText(),
               deserializeGroupIdentifiers(node),
            node.get("statusPath").getTextValue(),
            apacheHttpdMediaId == null ? null : apacheHttpdMediaId.asText());
    return jcws;
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:18,代碼來源:JsonCreateWebServer.java

示例13: manifestJsonValidate

import org.codehaus.jackson.JsonParser; //導入依賴的package包/類
/**
 * manifest.jsonのバリデート.
 * @param jp Jsonパーサー
 * @param mapper ObjectMapper
 * @return JSONManifestオブジェクト
 * @throws IOException データの読み込みに失敗した場合
 */
protected JSONManifest manifestJsonValidate(JsonParser jp, ObjectMapper mapper) throws IOException {
    // TODO BARファイルのバージョンチェック
    JSONManifest manifest = null;
    try {
        manifest = mapper.readValue(jp, JSONManifest.class);
    } catch (UnrecognizedPropertyException ex) {
        throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(
                "manifest.json unrecognized property");
    }
    if (manifest.getBarVersion() == null) {
        throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params("manifest.json#barVersion");
    }
    if (manifest.getBoxVersion() == null) {
        throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params("manifest.json#boxVersion");
    }
    if (manifest.getDefaultPath() == null) {
        throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params("manifest.json#DefaultPath");
    }
    return manifest;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:28,代碼來源:BarFileReadRunner.java

示例14: readJsonEntry

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

示例15: getRequestBody

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


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