use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project pinot by linkedin.
the class Summary method main.
public static void main(String[] argc) {
String oFileName = "Cube.json";
int answerSize = 10;
boolean doOneSideError = true;
int maxDimensionSize = 3;
Cube cube = null;
try {
cube = Cube.fromJson(oFileName);
System.out.println("Restored Cube:");
System.out.println(cube);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
Summary summary = new Summary(cube);
try {
SummaryResponse response = summary.computeSummary(answerSize, doOneSideError, maxDimensionSize);
System.out.print("JSon String: ");
System.out.println(new ObjectMapper().writeValueAsString(response));
System.out.println("Object String: ");
System.out.println(response.toString());
} catch (JsonProcessingException e) {
e.printStackTrace();
}
summary.testCorrectnessOfWowValues();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project hadoop by apache.
the class JsonSerDeser method fromBytes.
/**
* 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);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project hadoop by apache.
the class SlowPeerTracker method getJson.
/**
* Retrieve all valid reports as a JSON string.
* @return serialized representation of valid reports. null if
* serialization failed.
*/
public String getJson() {
Collection<ReportForJson> validReports = getJsonReports(MAX_NODES_TO_REPORT);
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.writeValueAsString(validReports);
} catch (JsonProcessingException e) {
// Failed to serialize. Don't log the exception call stack.
LOG.debug("Failed to serialize statistics" + e);
return null;
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project druid by druid-io.
the class LookupCoordinatorManager method updateAllOnHost.
void updateAllOnHost(final URL url, Map<String, Map<String, Object>> knownLookups) throws IOException, InterruptedException, ExecutionException {
final AtomicInteger returnCode = new AtomicInteger(0);
final AtomicReference<String> reasonString = new AtomicReference<>(null);
final byte[] bytes;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Loading up %d lookups to %s", knownLookups.size(), url);
}
bytes = smileMapper.writeValueAsBytes(knownLookups);
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
try (final InputStream result = httpClient.go(new Request(HttpMethod.POST, url).addHeader(HttpHeaders.Names.ACCEPT, SmileMediaTypes.APPLICATION_JACKSON_SMILE).addHeader(HttpHeaders.Names.CONTENT_TYPE, SmileMediaTypes.APPLICATION_JACKSON_SMILE).setContent(bytes), makeResponseHandler(returnCode, reasonString), lookupCoordinatorManagerConfig.getHostUpdateTimeout()).get()) {
if (!httpStatusIsSuccess(returnCode.get())) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
StreamUtils.copyAndClose(result, baos);
} catch (IOException e2) {
LOG.warn(e2, "Error reading response");
}
throw new IOException(String.format("Bad update request to [%s] : [%d] : [%s] Response: [%s]", url, returnCode.get(), reasonString.get(), StringUtils.fromUtf8(baos.toByteArray())));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Update on [%s], Status: %s reason: [%s]", url, returnCode.get(), reasonString.get());
}
final Map<String, Object> resultMap = smileMapper.readValue(result, MAP_STRING_OBJ_TYPE);
final Object missingValuesObject = resultMap.get(LookupModule.FAILED_UPDATES_KEY);
if (null == missingValuesObject) {
throw new IAE("Update result did not have field for [%s]", LookupModule.FAILED_UPDATES_KEY);
}
final Map<String, Object> missingValues = smileMapper.convertValue(missingValuesObject, MAP_STRING_OBJ_TYPE);
if (!missingValues.isEmpty()) {
throw new IAE("Lookups failed to update: %s", smileMapper.writeValueAsString(missingValues.keySet()));
} else {
LOG.debug("Updated all lookups on [%s]", url);
}
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project KaiZen-OpenAPI-Editor by RepreZen.
the class Model method parse.
public static Model parse(CompositeSchema schema, JsonNode document) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
String text = null;
try {
text = mapper.writeValueAsString(document);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return parseYaml(schema, text);
}
Aggregations