本文整理匯總了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);
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
}
示例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());
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}