com.fasterxml.jackson.core.JsonProcessingException#toString ( )源码实例Demo

下面列出了com.fasterxml.jackson.core.JsonProcessingException#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: java-sdk   文件: DaprBeanPostProcessor.java
/**
 * Subscribe to topics based on {@link Topic} annotations on the given class and any of ancestor classes.
 * @param clazz Controller class where {@link Topic} is expected.
 */
private static void subscribeToTopics(Class clazz) {
  if (clazz == null) {
    return;
  }

  subscribeToTopics(clazz.getSuperclass());
  for (Method method : clazz.getDeclaredMethods()) {
    Topic topic = method.getAnnotation(Topic.class);
    if (topic == null) {
      continue;
    }

    String route = topic.name();
    PostMapping mapping = method.getAnnotation(PostMapping.class);

    if (mapping != null && mapping.path() != null && mapping.path().length >= 1) {
      route = mapping.path()[0];
    }

    String topicName = topic.name();
    if ((topicName != null) && (topicName.length() > 0)) {
      try {
        TypeReference<HashMap<String, String>> typeRef
                = new TypeReference<HashMap<String, String>>() {};
        Map<String, String> metadata = MAPPER.readValue(topic.metadata(), typeRef);
        DaprRuntime.getInstance().addSubscribedTopic(topicName, route, metadata);
      } catch (JsonProcessingException e) {
        throw new IllegalArgumentException("Error while parsing metadata: " + e.toString());
      }
    }
  }
}
 
源代码2 项目: demo-java-9-migration   文件: MonitorServer.java
private static String toJson(Statistics stats) {
	try {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(StatisticsEntity.from(stats));
	} catch (JsonProcessingException ex) {
		// don't do this in real live
		return ex.toString();
	}
}
 
源代码3 项目: java-sdk   文件: JacksonConfigParser.java
@Override
public String toJson(Object src) throws JsonParseException {
    try {
        return objectMapper.writeValueAsString(src);
    } catch (JsonProcessingException e) {
        throw new JsonParseException("Serialization failed: " + e.toString());
    }
}
 
源代码4 项目: jdk9-jigsaw   文件: MonitorServer.java
private static String toJson(Statistics stats) {
	try {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(StatisticsEntity.from(stats));
	} catch (JsonProcessingException ex) {
		// don't do this in real live
		return ex.toString();
	}
}
 
源代码5 项目: jdk9-jigsaw   文件: MonitorServer.java
private static String toJson(Statistics stats) {
	try {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(StatisticsEntity.from(stats));
	} catch (JsonProcessingException ex) {
		// don't do this in real live
		return ex.toString();
	}
}
 
源代码6 项目: Wikidata-Toolkit   文件: StatementUpdate.java
/**
 * Returns a JSON serialization of the marked insertions and deletions of
 * statements, in the format required by the Wikibase "wbeditentity" action.
 *
 * @return JSON serialization of updates
 */
@JsonIgnore
public String getJsonUpdateString() {
	try {
		return mapper.writeValueAsString(this);
	} catch (JsonProcessingException e) {
		return ("Failed to serialize statement update to JSON: " + e.toString());
	}
}
 
源代码7 项目: TinCanJava   文件: JSONBase.java
@Override
public String toJSON(TCAPIVersion version, Boolean pretty) {
    ObjectWriter writer = Mapper.getWriter(pretty);
    try {
        return writer.writeValueAsString(this.toJSONNode(version));
    } catch (JsonProcessingException ex) {
        return "Exception in JSONBase Class: " + ex.toString();
    }
}
 
源代码8 项目: datacollector   文件: StandaloneRunner.java
private void validateAndSetStateTransition(String user, PipelineStatus toStatus, String message, Map<String, Object> attributes)
  throws PipelineStoreException, PipelineRunnerException {
  PipelineState fromState;
  PipelineState pipelineState;
  synchronized (this) {
    fromState = getState();
    checkState(VALID_TRANSITIONS.get(fromState.getStatus()).contains(toStatus), ContainerError.CONTAINER_0102,
      fromState.getStatus(), toStatus);
    long nextRetryTimeStamp = fromState.getNextRetryTimeStamp();
    int retryAttempt = fromState.getRetryAttempt();
    String metricString = null;
    if (toStatus == PipelineStatus.RETRY && fromState.getStatus() != PipelineStatus.CONNECTING) {
      retryAttempt = fromState.getRetryAttempt() + 1;
      if (retryAttempt > maxRetries && maxRetries != -1) {
        LOG.info("Retry attempt '{}' is greater than max no of retries '{}'", retryAttempt, maxRetries);
        toStatus = PipelineStatus.RUN_ERROR;
        retryAttempt = 0;
        nextRetryTimeStamp = 0;
      } else {
        nextRetryTimeStamp = RetryUtils.getNextRetryTimeStamp(retryAttempt, System.currentTimeMillis());
        isRetrying = true;
        metricsForRetry = getState().getMetrics();
      }
    } else if (!toStatus.isActive()) {
      retryAttempt = 0;
      nextRetryTimeStamp = 0;
    }
    if (!toStatus.isActive() || toStatus == PipelineStatus.DISCONNECTED
      || (toStatus == PipelineStatus.RETRY && fromState.getStatus() != PipelineStatus.CONNECTING)) {
      Object metrics = getMetrics();
      if (metrics != null) {
        ObjectMapper objectMapper = ObjectMapperFactory.get();
        try {
          metricString = objectMapper.writeValueAsString(metrics);
        } catch (JsonProcessingException e) {
          throw new PipelineStoreException(ContainerError.CONTAINER_0210, e.toString(), e);
        }
        getEventListenerManager().broadcastMetrics(getName(), metricString);
      }
      if (metricString == null) {
        metricString = getState().getMetrics();
      }
    }
    pipelineState =
      getPipelineStateStore().saveState(user, getName(), getRev(), toStatus, message, attributes, ExecutionMode.STANDALONE,
        metricString, retryAttempt, nextRetryTimeStamp);
    if (toStatus == PipelineStatus.RETRY) {
      retryFuture = scheduleForRetries(runnerExecutor);
    }
  }
  statsCollector.pipelineStatusChanged(toStatus, getPipelineConfigurationIfExists(), getPipeline());
  getEventListenerManager().broadcastStateChange(
      fromState,
      pipelineState,
      ThreadUsage.STANDALONE,
      OffsetFileUtil.getOffsets(getRuntimeInfo(), getName(), getRev())
  );
}
 
源代码9 项目: datacollector   文件: ClusterRunner.java
@VisibleForTesting
void validateAndSetStateTransition(String user, PipelineStatus toStatus, String message, Map<String, Object> attributes)
  throws PipelineStoreException, PipelineRunnerException {
  Utils.checkState(attributes!=null, "Attributes cannot be set to null");
  PipelineState fromState = getState();
  if (fromState.getStatus() == toStatus && toStatus != PipelineStatus.STARTING) {
    LOG.debug(Utils.format("Ignoring status '{}' as this is same as current status", fromState.getStatus()));
  } else {
    PipelineState pipelineState;
    synchronized (this) {
      fromState = getState();
      checkState(VALID_TRANSITIONS.get(fromState.getStatus()).contains(toStatus), ContainerError.CONTAINER_0102,
        fromState.getStatus(), toStatus);
      long nextRetryTimeStamp = fromState.getNextRetryTimeStamp();
      int retryAttempt = fromState.getRetryAttempt();
      if (toStatus == PipelineStatus.RUN_ERROR) {
        handleErrorCallbackFromSlaves(attributes);
      }
      if (toStatus == PipelineStatus.RUN_ERROR && shouldRetry) {
        toStatus = PipelineStatus.RETRY;
        checkState(VALID_TRANSITIONS.get(fromState.getStatus()).contains(toStatus), ContainerError.CONTAINER_0102,
          fromState.getStatus(), toStatus);
      }
      if (toStatus == PipelineStatus.RETRY && fromState.getStatus() != PipelineStatus.CONNECTING) {
        retryAttempt = fromState.getRetryAttempt() + 1;
        if (retryAttempt > maxRetries && maxRetries != -1) {
          LOG.info("Retry attempt '{}' is greater than max no of retries '{}'", retryAttempt, maxRetries);
          toStatus = PipelineStatus.RUN_ERROR;
          retryAttempt = 0;
          nextRetryTimeStamp = 0;
        } else {
          nextRetryTimeStamp = RetryUtils.getNextRetryTimeStamp(retryAttempt, System.currentTimeMillis());
        }
      } else if (!toStatus.isActive()) {
        retryAttempt = 0;
        nextRetryTimeStamp = 0;
      }
      ObjectMapper objectMapper = ObjectMapperFactory.get();
      String metricsJSONStr = null;
      if (!toStatus.isActive() || toStatus == PipelineStatus.DISCONNECTED) {
        Object metrics = getMetrics();
        if (metrics != null) {
          try {
            metricsJSONStr = objectMapper.writer().writeValueAsString(metrics);
          } catch (JsonProcessingException e) {
            throw new PipelineStoreException(ContainerError.CONTAINER_0210, e.toString(), e);
          }
        }
        if (metricsJSONStr == null) {
          metricsJSONStr = getState().getMetrics();
        }
      }
      pipelineState =
        getPipelineStateStore().saveState(user, getName(), getRev(), toStatus, message, attributes, getState().getExecutionMode(),
          metricsJSONStr, retryAttempt, nextRetryTimeStamp);
      if (toStatus == PipelineStatus.RETRY) {
        retryFuture = scheduleForRetries(runnerExecutor);
      }
    }
    // This should be out of sync block
    statsCollector.pipelineStatusChanged(toStatus, pipelineConf, null);
    if (getEventListenerManager() != null) {
      getEventListenerManager().broadcastStateChange(
          fromState,
          pipelineState,
          ThreadUsage.CLUSTER,
          OffsetFileUtil.getOffsets(getRuntimeInfo(), getName(), getRev())
      );
    }
  }
}