当前位置: 首页>>代码示例>>Java>>正文


Java JsonProcessingException类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:MappingJacksonHttpMessageConverter.java

示例2: 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;
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:17,代码来源:WindowDeserializer.java

示例3: 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;
    }
}
 
开发者ID:rbutenuth,项目名称:assert-object-equals-connector,代码行数:19,代码来源:AssertObjectEqualsConnector.java

示例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);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:39,代码来源:JsonSerDeser.java

示例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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:StateDeserializer.java

示例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 {
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:HadoopLogsAnalyzer.java

示例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);
    }
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:20,代码来源:ProducedEventsResponseDeserializer.java

示例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);
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:18,代码来源:TopicRecordDeserializer.java

示例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);
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:17,代码来源:SubscribeToTopicResponseDeserializer.java

示例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);
}
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:26,代码来源:InstantDeserializer.java

示例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);
    }
  }
}
 
开发者ID:apache,项目名称:apex-core,代码行数:20,代码来源:TupleRecorder.java

示例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


注:本文中的org.codehaus.jackson.JsonProcessingException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。