Search in sources :

Example 61 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project yorc-a4c-plugin by ystia.

the class RestClient method initObjectMapper.

private static void initObjectMapper() {
    RestClient.objectMapper = new ObjectMapper() {

        private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper = new com.fasterxml.jackson.databind.ObjectMapper();

        public <T> T readValue(String value, Class<T> valueType) {
            try {
                return jacksonObjectMapper.readValue(value, valueType);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public String writeValue(Object value) {
            try {
                return jacksonObjectMapper.writeValueAsString(value);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }
    };
    Unirest.setObjectMapper(RestClient.objectMapper);
}
Also used : IOException(java.io.IOException) JSONObject(org.json.JSONObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.mashape.unirest.http.ObjectMapper)

Example 62 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project loinc2hpo by monarch-initiative.

the class WriteToFile method toJson.

public static void toJson(Map<LoincId, UniversalLoinc2HPOAnnotation> annotationMap) {
    ObjectMapper mapper = new ObjectMapper();
    annotationMap.entrySet().forEach(p -> {
        try {
            System.out.println(mapper.writeValueAsString(p));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    });
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 63 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project swagger-parser by swagger-api.

the class OpenAPIV3Parser method readContents.

private SwaggerParseResult readContents(String swaggerAsString, List<AuthorizationValue> auth, ParseOptions options, String location) {
    if (swaggerAsString == null || swaggerAsString.trim().isEmpty()) {
        return SwaggerParseResult.ofError("Null or empty definition");
    }
    try {
        final ObjectMapper mapper = getRightMapper(swaggerAsString);
        JsonNode rootNode;
        final SwaggerParseResult deserializationUtilsResult = new SwaggerParseResult();
        if (options != null && options.isLegacyYamlDeserialization()) {
            rootNode = mapper.readTree(swaggerAsString);
        } else {
            try {
                rootNode = DeserializationUtils.deserializeIntoTree(swaggerAsString, location, options, deserializationUtilsResult);
            } catch (Exception e) {
                rootNode = mapper.readTree(swaggerAsString);
            }
        }
        SwaggerParseResult result;
        if (options != null) {
            result = parseJsonNode(location, rootNode, options);
        } else {
            result = parseJsonNode(location, rootNode);
        }
        if (result.getOpenAPI() != null) {
            result = resolve(result, auth, options, location);
        }
        if (deserializationUtilsResult.getMessages() != null) {
            for (String s : deserializationUtilsResult.getMessages()) {
                result.message(getParseErrorMessage(s, location));
            }
        }
        return result;
    } catch (JsonProcessingException e) {
        LOGGER.warn("Exception while parsing:", e);
        final String message = getParseErrorMessage(e.getOriginalMessage(), location);
        return SwaggerParseResult.ofError(message);
    } catch (Exception e) {
        LOGGER.warn("Exception while parsing:", e);
        final String message = getParseErrorMessage(e.getMessage(), location);
        return SwaggerParseResult.ofError(message);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReadContentException(io.swagger.v3.parser.exception.ReadContentException) EncodingNotSupportedException(io.swagger.v3.parser.exception.EncodingNotSupportedException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 64 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project UVMS-ActivityModule-APP by UnionVMS.

the class FACatchSummaryHelper method printJsonstructure.

public static String printJsonstructure(Object obj) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    String s = null;
    try {
        s = mapper.writeValueAsString(obj);
    } catch (JsonProcessingException e) {
        log.error("Exception while parsing JSON", e);
    }
    log.debug("json structure:-------->");
    log.debug("" + s);
    return s;
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 65 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project UVMS-ActivityModule-APP by UnionVMS.

the class JacksonSubclassSerializerTest method testSerializing.

@SneakyThrows
@Test
public void testSerializing() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    FishingActivityQuery fishQuery = new FishingActivityQuery();
    Map<SearchFilter, String> map = new HashMap<>();
    String val = "someVal";
    map.put(SearchFilter.VESSEL, val);
    fishQuery.setSearchCriteriaMap(map);
    String s = null;
    try {
        s = mapper.writeValueAsString(fishQuery);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    System.out.println(s);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) HashMap(java.util.HashMap) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)741 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)241 IOException (java.io.IOException)174 HashMap (java.util.HashMap)108 Map (java.util.Map)83 ArrayList (java.util.ArrayList)74 JsonNode (com.fasterxml.jackson.databind.JsonNode)73 Test (org.junit.Test)65 List (java.util.List)56 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)36 Collectors (java.util.stream.Collectors)30 InputStream (java.io.InputStream)26 Json (com.sequenceiq.cloudbreak.domain.json.Json)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 File (java.io.File)20 Function (java.util.function.Function)20 Logger (org.slf4j.Logger)20 Optional (java.util.Optional)19 Date (java.util.Date)18 Test (org.testng.annotations.Test)18