Search in sources :

Example 51 with JsonMappingException

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);
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) BeanProperty(com.fasterxml.jackson.databind.BeanProperty)

Example 52 with JsonMappingException

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;
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) MetricResult(org.apache.beam.sdk.metrics.MetricResult) MetricName(org.apache.beam.sdk.metrics.MetricName) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) MetricKey(org.apache.beam.sdk.metrics.MetricKey) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 53 with JsonMappingException

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();
    }
}
Also used : Message(software.amazon.awssdk.services.sqs.model.Message) ReceiveMessageRequest(software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) DeleteMessageRequest(software.amazon.awssdk.services.sqs.model.DeleteMessageRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 54 with JsonMappingException

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;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 55 with JsonMappingException

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);
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)185 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)93 IOException (java.io.IOException)80 JsonParseException (com.fasterxml.jackson.core.JsonParseException)57 Test (org.junit.Test)45 ATTest (org.jboss.eap.additional.testsuite.annotations.ATTest)33 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)24 ArrayList (java.util.ArrayList)16 Map (java.util.Map)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 File (java.io.File)15 HashMap (java.util.HashMap)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 InputStream (java.io.InputStream)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 List (java.util.List)8 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 Test (org.junit.jupiter.api.Test)6