Search in sources :

Example 71 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project apache-kafka-on-k8s by banzaicloud.

the class VerifiableSinkTask method put.

@Override
public void put(Collection<SinkRecord> records) {
    long nowMs = System.currentTimeMillis();
    for (SinkRecord record : records) {
        Map<String, Object> data = new HashMap<>();
        data.put("name", name);
        // VerifiableSourceTask's input task (source partition)
        data.put("task", record.key());
        data.put("sinkTask", id);
        data.put("topic", record.topic());
        data.put("time_ms", nowMs);
        data.put("seqno", record.value());
        data.put("offset", record.kafkaOffset());
        String dataJson;
        try {
            dataJson = JSON_SERDE.writeValueAsString(data);
        } catch (JsonProcessingException e) {
            dataJson = "Bad data can't be written as json: " + e.getMessage();
        }
        System.out.println(dataJson);
        unflushed.add(data);
    }
}
Also used : HashMap(java.util.HashMap) SinkRecord(org.apache.kafka.connect.sink.SinkRecord) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 72 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project cytoscape-impl by cytoscape.

the class AbstractCustomGraphics2 method set.

public synchronized void set(final String key, Object value) {
    if (key == null)
        throw new IllegalArgumentException("'key' must not be null.");
    final Class<?> type = getSettingType(key);
    if (type != null) {
        if (value != null) {
            // It's OK; just take the value as it is.
            boolean correctType = type == Array.class && value.getClass().isArray() && value.getClass().getComponentType() == getSettingElementType(key);
            correctType = correctType || type.isAssignableFrom(value.getClass());
            if (!correctType) {
                final ObjectMapper om = getObjectMapper();
                String json = value.toString();
                if (type != List.class) {
                    try {
                        json = om.writeValueAsString(value);
                    } catch (JsonProcessingException e) {
                        logger.error("Cannot parse JSON field " + key, e);
                    }
                }
                value = PropertiesJsonDeserializer.readValue(key, json, om, this);
            }
        }
        properties.put(key, value);
    }
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 73 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project cytoscape-impl by cytoscape.

the class AbstractCustomGraphics2 method toSerializableString.

@Override
public String toSerializableString() {
    String output = "";
    try {
        final ObjectMapper om = getObjectMapper();
        output = om.writeValueAsString(this.properties);
        output = getId() + ":" + output;
    } catch (JsonProcessingException e) {
        logger.error("Cannot create JSON from custom graphics", e);
    }
    return output;
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 74 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project metalnx-web by irods-contrib.

the class UserBookmarkController method bookmarksPaginated.

@RequestMapping(value = "/bookmarksPaginated")
@ResponseBody
public String bookmarksPaginated(final HttpServletRequest request) {
    int draw = Integer.parseInt(request.getParameter("draw"));
    int start = Integer.parseInt(request.getParameter("start"));
    int length = Integer.parseInt(request.getParameter("length"));
    String searchString = request.getParameter("search[value]");
    int orderColumn = Integer.parseInt(request.getParameter("order[0][column]"));
    String orderDir = request.getParameter("order[0][dir]");
    boolean onlyCollections = Boolean.parseBoolean(request.getParameter("onlyCollections"));
    String loggedUsername = irodsServices.getCurrentUser();
    String loggedUserZoneName = irodsServices.getCurrentUserZone();
    DataGridUser user = userService.findByUsernameAndAdditionalInfo(loggedUsername, loggedUserZoneName);
    String[] orderBy = { "name", "path", "created_at", "is_collection" };
    // checking if there is another column to order by
    boolean has2ndColumnToOrderBy = request.getParameter("order[1][column]") != null;
    List<DataGridUserBookmark> userBookmarks = null;
    if (has2ndColumnToOrderBy) {
        List<String> orderByList = new ArrayList<String>();
        List<String> orderDirList = new ArrayList<String>();
        int firstCol = Integer.parseInt(request.getParameter("order[0][column]"));
        int secondCol = Integer.parseInt(request.getParameter("order[1][column]"));
        orderByList.add(orderBy[firstCol]);
        orderDirList.add(request.getParameter("order[0][dir]"));
        orderByList.add(orderBy[secondCol]);
        orderDirList.add(request.getParameter("order[1][dir]"));
        userBookmarks = userBookmarkService.findBookmarksPaginated(user, start, length, searchString, orderByList, orderDirList, onlyCollections);
    } else {
        userBookmarks = userBookmarkService.findBookmarksPaginated(user, start, length, searchString, orderBy[orderColumn], orderDir, onlyCollections);
    }
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonResponse = new HashMap<String, Object>();
    String jsonString = "";
    if ("".equals(searchString)) {
        totalUserBookmarks = user.getBookmarks().size();
        totalUserBookmarksFiltered = user.getBookmarks().size();
    } else {
        totalUserBookmarksFiltered = userBookmarks.size();
    }
    jsonResponse.put("draw", String.valueOf(draw));
    jsonResponse.put("recordsTotal", String.valueOf(totalUserBookmarks));
    jsonResponse.put("recordsFiltered", String.valueOf(totalUserBookmarksFiltered));
    jsonResponse.put("data", userBookmarks);
    try {
        jsonString = mapper.writeValueAsString(jsonResponse);
    } catch (JsonProcessingException e) {
        logger.error("Could not parse user bookmarks to json: {}", e.getMessage());
    }
    return jsonString;
}
Also used : HashMap(java.util.HashMap) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) ArrayList(java.util.ArrayList) DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 75 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project apiee by phillip-kruger.

the class SwaggerCache method generateJson.

private String generateJson(int hash, final Set<Class<?>> classes, URL url) {
    log.log(Level.FINEST, "Generating {0} response from context", url);
    Swagger swagger = createSwagger(classes, url);
    try {
        String swaggerJson = Json.pretty().writeValueAsString(swagger);
        swaggerMap.put(hash, swaggerJson);
        return swaggerJson;
    } catch (JsonProcessingException ex) {
        log.log(Level.WARNING, "Could not generate {0} - {1}", new Object[] { url.toString(), ex.getMessage() });
    }
    log.log(Level.WARNING, "Could not generate {0} - null", new Object[] { url.toString() });
    return null;
}
Also used : Swagger(io.swagger.models.Swagger) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

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