use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project beam by apache.
the class PipelineOptionsFactory method computeCustomSerializerForMethod.
private static Optional<JsonSerializer<Object>> computeCustomSerializerForMethod(Method method) {
try {
BeanProperty prop = createBeanProperty(method);
AnnotatedMember annotatedMethod = prop.getMember();
Object maybeSerializerClass = SERIALIZER_PROVIDER.getAnnotationIntrospector().findSerializer(annotatedMethod);
return Optional.fromNullable(SERIALIZER_PROVIDER.serializerInstance(annotatedMethod, maybeSerializerClass));
} catch (JsonMappingException e) {
throw new RuntimeException(e);
}
}
use of org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project aws-doc-sdk-examples by awsdocs.
the class VideoDetect method getLabelJob.
public static void getLabelJob(RekognitionClient rekClient, SqsClient sqs, String queueUrl) {
List<Message> messages = null;
ReceiveMessageRequest messageRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).build();
try {
messages = sqs.receiveMessage(messageRequest).messages();
if (!messages.isEmpty()) {
for (Message message : messages) {
String notification = message.body();
// Get the status and job id from the notification
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonMessageTree = mapper.readTree(notification);
JsonNode messageBodyText = jsonMessageTree.get("Message");
ObjectMapper operationResultMapper = new ObjectMapper();
JsonNode jsonResultTree = operationResultMapper.readTree(messageBodyText.textValue());
JsonNode operationJobId = jsonResultTree.get("JobId");
JsonNode operationStatus = jsonResultTree.get("Status");
System.out.println("Job found in JSON is " + operationJobId);
DeleteMessageRequest deleteMessageRequest = DeleteMessageRequest.builder().queueUrl(queueUrl).build();
String jobId = operationJobId.textValue();
if (startJobId.compareTo(jobId) == 0) {
System.out.println("Job id: " + operationJobId);
System.out.println("Status : " + operationStatus.toString());
if (operationStatus.asText().equals("SUCCEEDED"))
GetResultsLabels(rekClient);
else
System.out.println("Video analysis failed");
sqs.deleteMessage(deleteMessageRequest);
} else {
System.out.println("Job received was not job " + startJobId);
sqs.deleteMessage(deleteMessageRequest);
}
}
}
} catch (RekognitionException e) {
e.getMessage();
System.exit(1);
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project OpenRefine by OpenRefine.
the class DatabaseUtils method getSavedConnections.
/**
* GET saved connections
* @return
*/
public static List<DatabaseConfiguration> getSavedConnections() {
ObjectMapper mapper = new ObjectMapper();
try {
String filename = getExtensionFilePath();
File file = new File(filename);
if (!file.exists()) {
// logger.debug("saved connections file not found, creating new: {}", filename);
String dirPath = getExtensionFolder();
File dirFile = new File(dirPath);
boolean dirExists = true;
if (!dirFile.exists()) {
dirExists = dirFile.mkdir();
}
if (dirExists) {
SavedConnectionContainer sc = new SavedConnectionContainer(new ArrayList<DatabaseConfiguration>());
mapper.writerWithDefaultPrettyPrinter().writeValue(new File(filename), sc);
return sc.getSavedConnections();
// return decryptAll(sc.getSavedConnections());
}
}
// logger.debug("saved connections file found {}", filename);
SavedConnectionContainer savedConnectionContainer = mapper.readValue(new File(filename), SavedConnectionContainer.class);
// return decryptAll(savedConnectionContainer.getSavedConnections());
return savedConnectionContainer.getSavedConnections();
} catch (JsonParseException e) {
logger.error("JsonParseException: {}", e);
} catch (JsonMappingException e) {
logger.error("JsonMappingException: {}", e);
} catch (IOException e) {
logger.error("IOException: {}", e);
}
return null;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project spring-boot by spring-projects.
the class JsonObjectSerializer method serialize.
@Override
public final void serialize(T value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
try {
jgen.writeStartObject();
serializeObject(value, jgen, provider);
jgen.writeEndObject();
} catch (Exception ex) {
if (ex instanceof IOException) {
throw (IOException) ex;
}
throw new JsonMappingException(jgen, "Object serialize error", ex);
}
}
Aggregations