use of com.fasterxml.jackson.databind.JsonMappingException in project beam by apache.
the class MetricsHttpSink method serializeMetrics.
private String serializeMetrics(MetricQueryResults metricQueryResults) throws Exception {
SimpleModule module = new JodaModule();
module.addSerializer(new MetricNameSerializer(MetricName.class));
module.addSerializer(new MetricKeySerializer(MetricKey.class));
module.addSerializer(new MetricResultSerializer(MetricResult.class));
objectMapper.registerModule(module);
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
// need to register a filter as soon as @JsonFilter annotation is specified.
// So specify an pass through filter
SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.serializeAll();
SimpleFilterProvider filterProvider = new SimpleFilterProvider();
filterProvider.addFilter("committedMetrics", filter);
objectMapper.setFilterProvider(filterProvider);
String result;
try {
result = objectMapper.writeValueAsString(metricQueryResults);
} catch (JsonMappingException exception) {
if ((exception.getCause() instanceof UnsupportedOperationException) && exception.getCause().getMessage().contains("committed metrics")) {
filterProvider.removeFilter("committedMetrics");
filter = SimpleBeanPropertyFilter.serializeAllExcept("committed");
filterProvider.addFilter("committedMetrics", filter);
result = objectMapper.writeValueAsString(metricQueryResults);
} else {
throw exception;
}
}
return result;
}
use of com.fasterxml.jackson.databind.JsonMappingException in project druid by druid-io.
the class QueryGranularityTest method testSerializePeriod.
@Test
public void testSerializePeriod() throws Exception {
ObjectMapper mapper = new DefaultObjectMapper();
String json = "{ \"type\": \"period\", \"period\": \"P1D\" }";
Granularity gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), null, null), gran);
json = "{ \"type\": \"period\", \"period\": \"P1D\"," + "\"timeZone\": \"America/Los_Angeles\", \"origin\": \"1970-01-01T00:00:00Z\"}";
gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), new DateTime(0L), DateTimeZone.forID("America/Los_Angeles")), gran);
PeriodGranularity expected = new PeriodGranularity(new Period("P1D"), new DateTime("2012-01-01"), DateTimeZone.forID("America/Los_Angeles"));
String jsonOut = mapper.writeValueAsString(expected);
Assert.assertEquals(expected, mapper.readValue(jsonOut, Granularity.class));
String illegalJson = "{ \"type\": \"period\", \"period\": \"P0D\" }";
try {
mapper.readValue(illegalJson, Granularity.class);
Assert.fail();
} catch (JsonMappingException e) {
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project druid by druid-io.
the class CoordinatorDynamicConfigTest method testSerdeWithKillAllDataSources.
@Test
public void testSerdeWithKillAllDataSources() throws Exception {
String jsonStr = "{\n" + " \"millisToWaitBeforeDeleting\": 1,\n" + " \"mergeBytesLimit\": 1,\n" + " \"mergeSegmentsLimit\" : 1,\n" + " \"maxSegmentsToMove\": 1,\n" + " \"replicantLifetime\": 1,\n" + " \"replicationThrottleLimit\": 1,\n" + " \"balancerComputeThreads\": 2, \n" + " \"emitBalancingStats\": true,\n" + " \"killAllDataSources\": true\n" + "}\n";
ObjectMapper mapper = TestHelper.getObjectMapper();
CoordinatorDynamicConfig actual = mapper.readValue(mapper.writeValueAsString(mapper.readValue(jsonStr, CoordinatorDynamicConfig.class)), CoordinatorDynamicConfig.class);
Assert.assertEquals(new CoordinatorDynamicConfig(1, 1, 1, 1, 1, 1, 2, true, ImmutableSet.of(), true), actual);
//ensure whitelist is empty when killAllDataSources is true
try {
jsonStr = "{\n" + " \"killDataSourceWhitelist\": [\"test1\",\"test2\"],\n" + " \"killAllDataSources\": true\n" + "}\n";
mapper.readValue(jsonStr, CoordinatorDynamicConfig.class);
Assert.fail("deserialization should fail.");
} catch (JsonMappingException e) {
Assert.assertTrue(e.getCause() instanceof IAE);
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project ambrose by twitter.
the class HRavenStatsReadService method getEventsSinceId.
@SuppressWarnings("rawtypes")
@Override
public List<Event> getEventsSinceId(String workflowId, int eventId, int maxEvents) throws IOException {
Preconditions.checkArgument(maxEvents > 0);
WorkflowId id = WorkflowId.parseString(workflowId);
FlowEventKey flowEventKey = new FlowEventKey(toFlowKey(id), eventId);
List<FlowEvent> flowEventList = flowEventService.getFlowEventsSince(flowEventKey);
// TODO push this limit into the FlowEventService
int numElems = 0;
List<Event> workflowEvents = Lists.newArrayListWithCapacity(maxEvents);
for (FlowEvent flowEvent : flowEventList) {
if (numElems >= maxEvents) {
break;
}
String eventDataJson = flowEvent.getEventDataJSON();
try {
Event event = Event.fromJson(eventDataJson);
numElems++;
workflowEvents.add(event);
} catch (JsonMappingException e) {
LOG.error("Could not deserialize json: " + eventDataJson, e);
}
}
return workflowEvents;
}
use of com.fasterxml.jackson.databind.JsonMappingException in project torodb by torodb.
the class AbstractBackendSerializer method depositSchemaProperty.
private void depositSchemaProperty(JsonObjectFormatVisitor v, String name, JavaType type) throws JsonMappingException {
BeanProperty prop = new BeanProperty.Std(PropertyName.construct(name), type, null, null, null, PropertyMetadata.STD_OPTIONAL) {
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor v) {
try {
if (v != null) {
if (isRequired()) {
v.property(this);
} else {
v.optionalProperty(this);
}
}
} catch (JsonMappingException jsonMappingException) {
throw new RuntimeException(jsonMappingException);
}
}
};
prop.depositSchemaProperty(v);
}
Aggregations