use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project jhipster-sample-app-websocket by jhipster.
the class TestUtil method convertObjectToJsonBytes.
/**
* Convert an object to JSON byte array.
*
* @param object
* the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project jhipster-sample-app-mongodb by jhipster.
the class TestUtil method convertObjectToJsonBytes.
/**
* Convert an object to JSON byte array.
*
* @param object
* the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project jhipster-sample-app-hazelcast by jhipster.
the class TestUtil method convertObjectToJsonBytes.
/**
* Convert an object to JSON byte array.
*
* @param object
* the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project hello-world by haoziapple.
the class TestUtil method convertObjectToJsonBytes.
/**
* Convert an object to JSON byte array.
*
* @param object
* the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project presto by prestodb.
the class PrometheusQueryResponse method parsePrometheusQueryResponse.
private void parsePrometheusQueryResponse(InputStream response) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
JsonParser parser = new JsonFactory().createParser(response);
while (!parser.isClosed()) {
JsonToken jsonToken = parser.nextToken();
if (FIELD_NAME.equals(jsonToken)) {
if (parser.getCurrentName().equals(parseResultStatus)) {
parser.nextToken();
if (parser.getValueAsString().equals(parseResultSuccess)) {
this.status = true;
while (!parser.isClosed()) {
parser.nextToken();
if (FIELD_NAME.equals(jsonToken)) {
if (parser.getCurrentName().equals(parseResultType)) {
parser.nextToken();
resultType = ResultType.valueOf(parser.getValueAsString());
}
if (parser.getCurrentName().equals(parseResult)) {
parser.nextToken();
ArrayNode node = mapper.readTree(parser);
result = node.toString();
break;
}
}
}
} else {
// error path
String parsedStatus = parser.getValueAsString();
// parsing json is key-value based, so first nextToken is advanced to the key, nextToken advances to the value.
// for "errorType" key
parser.nextToken();
// for "errorType" key's value
parser.nextToken();
errorType = parser.getValueAsString();
// advance to "error" key
parser.nextToken();
// advance to "error" key's value
parser.nextToken();
error = parser.getValueAsString();
throw new PrestoException(PROMETHEUS_PARSE_ERROR, "Unable to parse Prometheus response: " + parsedStatus + " " + errorType + " " + error);
}
}
}
if (result != null) {
break;
}
}
if (result != null && resultType != null) {
switch(resultType) {
case matrix:
case vector:
results = mapper.readValue(result, new TypeReference<List<PrometheusMetricResult>>() {
});
break;
case scalar:
case string:
PrometheusTimeSeriesValue stringOrScalarResult = mapper.readValue(result, new TypeReference<PrometheusTimeSeriesValue>() {
});
Map<String, String> madeUpMetricHeader = new HashMap<>();
madeUpMetricHeader.put("__name__", resultType.toString());
PrometheusTimeSeriesValueArray timeSeriesValues = new PrometheusTimeSeriesValueArray(singletonList(stringOrScalarResult));
results = singletonList(new PrometheusMetricResult(madeUpMetricHeader, timeSeriesValues));
}
}
}
Aggregations