本文整理汇总了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;
}