Refine search
/** * @return Formatted JSON representation of this StateMachine. May be provided to API calls (see {@link * com.amazonaws.services.stepfunctions.AWSStepFunctions}). */ public String toPrettyJson() { try { return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(this); } catch (JsonProcessingException e) { throw new SdkClientException("Could not serialize state machine.", e); } }
public String serialize(Object obj, boolean pretty) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); if (pretty) { return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj); } return mapper.writeValueAsString(obj); }
@VisibleForTesting public String dumpJson() throws Exception { ObjectMapper jsonMapper = new ObjectMapper().registerModule( new MetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false)); return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(metricRegistry); }
@VisibleForTesting public String dumpJson() throws Exception { ObjectMapper jsonMapper = new ObjectMapper() .registerModule(new MetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false)); return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(metricRegistry); }
@Override public void start(long period, TimeUnit unit) { // Create metrics directory if it is not present if (!metricsDir.toFile().exists()) { LOG.warn("Metrics directory {} does not exist, creating one", metricsDir); try { // createDirectories creates all non-existent parent directories Files.createDirectories(metricsDir, DIR_ATTRS); } catch (IOException e) { LOG.warn("Failed to initialize JSON reporter: failed to create directory {}: {}", metricsDir, e.getMessage()); return; } } jsonWriter = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false)).writerWithDefaultPrettyPrinter(); super.start(period, unit); }
public String exportReportOverviewToJsonAsString(ReportOverview reportOverview) throws JsonProcessingException { return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(reportOverview); }
private String serializedConfiguration(JsonNode config) throws JsonProcessingException{ ObjectMapper mapper = new ObjectMapper(); ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter(); return config.isMissingNode() ? null : writer.writeValueAsString(config); }
public JsonFileMetricsReporter(MetricRegistry registry, HiveConf conf) { this.metricRegistry = registry; this.jsonWriter = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false)).writerWithDefaultPrettyPrinter(); interval = conf.getTimeVar(HiveConf.ConfVars.HIVE_METRICS_JSON_FILE_INTERVAL, TimeUnit.MILLISECONDS); String pathString = conf.getVar(HiveConf.ConfVars.HIVE_METRICS_JSON_FILE_LOCATION); path = Paths.get(pathString).toAbsolutePath(); LOGGER.info("Reporting metrics to {}", path); // We want to use metricsDir in the same directory as the destination file to support atomic // move of temp file to the destination metrics file metricsDir = path.getParent(); }
public static <T> String parseInPrettyMode(T obj) { try { return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(obj); } catch (JsonProcessingException e) { Throwables.throwIfUnchecked(e); throw new IllegalArgumentException(e); } }
/** * * @param result a Map<String, Object> contains http request/response info which needs to be logged. * @param loggerFunc Consuer<T> getLoggerFuncBasedOnLevel(config.getLogLevel()) */ private static void logResultUsingJson(Map<String, Object> result, Consumer<String> loggerFunc) { ObjectMapper mapper = new ObjectMapper(); String resultJson = ""; try { resultJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(result); } catch (JsonProcessingException e) { logger.error(e.toString()); } if(StringUtils.isNotBlank(resultJson)){ loggerFunc.accept("Dump Info:\n" + resultJson); } }
public JsonPrinter(PrintStream out) { this.out = out; mapper = new ObjectMapper(); mapper.getSerializationConfig().without(SerializationFeature.WRITE_NULL_MAP_VALUES); prettyPrintingWriter = mapper.writerWithDefaultPrettyPrinter(); }
@Override public Optional<String> serializeExampleRequest(String serviceName, String methodName, Object exampleRequest) { try { return Optional.of(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(exampleRequest)); } catch (JsonProcessingException e) { // Ignore the exception and just return Optional.empty(). } return Optional.empty(); } }
private void logBytes(Pair<Object, byte[]> pair) { ObjectMapper objectMapper = new ObjectMapper(); String buffer = new String(pair.getRight(), 4, pair.getRight().length - 4, StandardCharsets.UTF_8); logger.write(buffer); try { logger.write(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectMapper.readValue(buffer, Object.class))); } catch (IOException e) { e.printStackTrace(); } logger.write(InternalUtils.hexDump(32, pair.getRight(), 0, pair.getRight().length)); }
public JsonFileMetricsReporter(MetricRegistry registry, KylinConfig conf) { this.metricRegistry = registry; this.jsonWriter = new ObjectMapper() .registerModule(new MetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false)) .writerWithDefaultPrettyPrinter(); executorService = Executors.newSingleThreadScheduledExecutor(); this.conf = conf; frequency = KylinConfig.getInstanceFromEnv().getMetricsReporterFrequency(); pathString = KylinConfig.getInstanceFromEnv().getMetricsFileLocation(); path = new Path(pathString); }
@Override public TaskStatus apply(TaskStatus taskStatus) { try { log.info( "Task completed with status: %s", jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskStatus) ); final File statusFileParent = statusFile.getParentFile(); if (statusFileParent != null) { FileUtils.forceMkdir(statusFileParent); } jsonMapper.writeValue(statusFile, taskStatus); return taskStatus; } catch (Exception e) { throw Throwables.propagate(e); } } }
protected static String prettyJson(JsonNode json) { try { return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(json); } catch (Throwable t) { Testing.printError(t); fail(t.getMessage()); assert false : "Will not get here"; return null; } }
import java.io.IOException; import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jsonSchema.JsonSchema; import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; public class JacksonProgram { public static void main(String[] args) throws IOException { ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(Entity.class, visitor); JsonSchema schema = visitor.finalSchema(); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema)); } }
public String serialize(MessageLogEntry messageLogEntry) { try { return objectMapper .writerWithDefaultPrettyPrinter() .writeValueAsString(messageLogEntry); } catch (Exception e) { mockServerLogger.error(String.format("Exception while serializing messageLogEntry to JSON with value %s", messageLogEntry), e); throw new RuntimeException(String.format("Exception while serializing messageLogEntry to JSON with value %s", messageLogEntry), e); } }
private void init(ProducerConfigurationData conf) { ObjectMapper m = new ObjectMapper(); m.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); ObjectWriter w = m.writerWithDefaultPrettyPrinter(); log.info("Starting Pulsar producer perf with config: {}", w.writeValueAsString(conf)); log.info("Pulsar client config: {}", w.withoutAttribute("authentication").writeValueAsString(pulsarClient.getConfiguration())); } catch (IOException e) { log.error("Failed to dump config info: {}", e);
/** * By allowing the user to provide an ObjectMapper, it can be configured with * knowledge of how to marshall and un-marshall your domain objects. * * @param objectMapper a configured Jackson ObjectMapper */ public JsonUtilImpl( ObjectMapper objectMapper ) { this.objectMapper = objectMapper == null ? new ObjectMapper() : objectMapper; configureStockJoltObjectMapper( this.objectMapper ); prettyPrintWriter = this.objectMapper.writerWithDefaultPrettyPrinter(); }