本文整理匯總了Java中org.codehaus.jackson.JsonProcessingException類的典型用法代碼示例。如果您正苦於以下問題:Java JsonProcessingException類的具體用法?Java JsonProcessingException怎麽用?Java JsonProcessingException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JsonProcessingException類屬於org.codehaus.jackson包,在下文中一共展示了JsonProcessingException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeInternal
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
JsonGenerator jsonGenerator =
this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
// A workaround for JsonGenerators not applying serialization features
// https://github.com/FasterXML/jackson-databind/issues/12
if (this.objectMapper.getSerializationConfig().isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) {
jsonGenerator.useDefaultPrettyPrinter();
}
try {
if (this.jsonPrefix != null) {
jsonGenerator.writeRaw(this.jsonPrefix);
}
this.objectMapper.writeValue(jsonGenerator, object);
}
catch (JsonProcessingException ex) {
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
}
}
示例2: convert2Object
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
private Object convert2Object(Object value) throws JsonProcessingException, IOException {
if (value == null) {
return null;
} else if (value instanceof InputStream) {
return new ObjectMapper().reader(Object.class).readValue((InputStream) value);
} else if (value instanceof byte[]) {
return new ObjectMapper().reader(Object.class).readValue((byte[]) value);
} else if (value instanceof CharSequence) {
String trimmed = ((CharSequence) value).toString().trim();
if (trimmed.startsWith("[") || trimmed.startsWith("{")) {
return new ObjectMapper().reader(Object.class).readValue(trimmed);
} else {
return value;
}
} else {
return value;
}
}
示例3: deserialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的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;
}
示例4: fromBytes
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
/**
* Deserialize from a byte array, optionally checking for a marker string.
* <p>
* If the marker parameter is supplied (and not empty), then its presence
* will be verified before the JSON parsing takes place; it is a fast-fail
* check. If not found, an {@link InvalidRecordException} exception will be
* raised
* @param path path the data came from
* @param bytes byte array
* @param marker an optional string which, if set, MUST be present in the
* UTF-8 parsed payload.
* @return The parsed record
* @throws IOException all problems
* @throws EOFException not enough data
* @throws InvalidRecordException if the JSON parsing failed.
* @throws NoRecordException if the data is not considered a record: either
* it is too short or it did not contain the marker string.
*/
public T fromBytes(String path, byte[] bytes, String marker)
throws IOException, NoRecordException, InvalidRecordException {
int len = bytes.length;
if (len == 0 ) {
throw new NoRecordException(path, E_NO_DATA);
}
if (StringUtils.isNotEmpty(marker) && len < marker.length()) {
throw new NoRecordException(path, E_DATA_TOO_SHORT);
}
String json = new String(bytes, 0, len, UTF_8);
if (StringUtils.isNotEmpty(marker)
&& !json.contains(marker)) {
throw new NoRecordException(path, E_MISSING_MARKER_STRING + marker);
}
try {
return fromJson(json);
} catch (JsonProcessingException e) {
throw new InvalidRecordException(path, e.toString(), e);
}
}
示例5: deserialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的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);
}
示例6: processParsedLine
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
private void processParsedLine(ParsedLine line)
throws JsonProcessingException, IOException {
if (!collecting) {
// "Job", "MapAttempt", "ReduceAttempt", "Task"
LogRecordType myType = line.getType();
if (myType == canonicalJob) {
processJobLine(line);
} else if (myType == canonicalTask) {
processTaskLine(line);
} else if (myType == canonicalMapAttempt) {
processMapAttemptLine(line);
} else if (myType == canonicalReduceAttempt) {
processReduceAttemptLine(line);
} else {
}
}
}
示例7: deserialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的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);
}
}
示例8: deserialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的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);
}
示例9: deserialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的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);
}
示例10: deserialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
@Override
public Instant deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Instant(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser();
final DateTime dateTime = formatter.parseDateTime(str);
return new Instant(dateTime.getMillis());
}
throw ctxt.mappingException(Instant.class);
}
示例11: publishTupleData
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
private void publishTupleData(int portId, Object obj)
{
try {
if (wsClient != null && wsClient.isConnectionOpen()) {
HashMap<String, Object> map = new HashMap<>();
map.put("portId", String.valueOf(portId));
map.put("windowId", currentWindowId);
map.put("tupleCount", totalTupleCount);
map.put("data", obj);
wsClient.publish(recordingNameTopic, map);
}
} catch (Exception ex) {
if (ex instanceof JsonProcessingException) {
checkLogTuple(ex, "publish", obj);
} else {
logger.warn("Error publishing tuple", ex);
}
}
}
示例12: serialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
/**
* Performs the serialization of a OFFeaturesReply object
*/
@Override
public void serialize(OFFeaturesReply reply, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException {
jGen.writeStartObject();
jGen.writeNumberField("actions", reply.getActions());
jGen.writeNumberField("buffers", reply.getBuffers());
jGen.writeNumberField("capabilities", reply.getCapabilities());
jGen.writeStringField("datapathId", HexString.toHexString(reply.getDatapathId()));
jGen.writeNumberField("length", reply.getLength());
serializer.defaultSerializeField("ports", reply.getPorts(), jGen);
jGen.writeNumberField("tables", reply.getTables());
jGen.writeStringField("type", reply.getType().toString());
jGen.writeNumberField("version", reply.getVersion());
jGen.writeNumberField("xid", reply.getXid());
jGen.writeEndObject();
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:19,代碼來源:OFFeaturesReplyJSONSerializer.java
示例13: serialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
/**
* Performs the serialization of a OneComponentTime object
*/
@Override
public void serialize(CumulativeTimeBucket ctb,
JsonGenerator jGen,
SerializerProvider serializer)
throws IOException, JsonProcessingException {
jGen.writeStartObject();
Timestamp ts = new Timestamp(ctb.getStartTimeNs()/1000000);
jGen.writeStringField("start-time", ts.toString());
jGen.writeStringField("current-time",
new Timestamp(System.currentTimeMillis()).toString());
jGen.writeNumberField("total-packets", ctb.getTotalPktCnt());
jGen.writeNumberField("average", ctb.getAverageProcTimeNs());
jGen.writeNumberField("min", ctb.getMinTotalProcTimeNs());
jGen.writeNumberField("max", ctb.getMaxTotalProcTimeNs());
jGen.writeNumberField("std-dev", ctb.getTotalSigmaProcTimeNs());
jGen.writeArrayFieldStart("modules");
for (OneComponentTime oct : ctb.getModules()) {
serializer.defaultSerializeValue(oct, jGen);
}
jGen.writeEndArray();
jGen.writeEndObject();
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:26,代碼來源:CumulativeTimeBucketJSONSerializer.java
示例14: serialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
@Override
public void serialize(VirtualNetwork vNet, JsonGenerator jGen,
SerializerProvider serializer) throws IOException,
JsonProcessingException {
jGen.writeStartObject();
jGen.writeStringField("name", vNet.name);
jGen.writeStringField("guid", vNet.guid);
jGen.writeStringField("gateway", vNet.gateway);
jGen.writeArrayFieldStart("mac");
Iterator<MACAddress> hit = vNet.hosts.iterator();
while (hit.hasNext())
jGen.writeString(hit.next().toString());
jGen.writeEndArray();
jGen.writeEndObject();
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:19,代碼來源:VirtualNetworkSerializer.java
示例15: serialize
import org.codehaus.jackson.JsonProcessingException; //導入依賴的package包/類
/**
* Performs the serialization of a EventHistory.BaseInfo object
*/
@Override
public void serialize(EventHistoryBaseInfo base_info, JsonGenerator jGen,
SerializerProvider serializer)
throws IOException, JsonProcessingException {
jGen.writeStartObject();
jGen.writeNumberField("Idx", base_info.getIdx());
Timestamp ts = new Timestamp(base_info.getTime_ms());
String tsStr = ts.toString();
while (tsStr.length() < 23) {
tsStr = tsStr.concat("0");
}
jGen.writeStringField("Time", tsStr);
jGen.writeStringField("State", base_info.getState().name());
String acStr = base_info.getAction().name().toLowerCase();
// Capitalize the first letter
acStr = acStr.substring(0,1).toUpperCase().concat(acStr.substring(1));
jGen.writeStringField("Action", acStr);
jGen.writeEndObject();
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:23,代碼來源:EventHistoryBaseInfoJSONSerializer.java