Search in sources :

Example 41 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method getAtlasMappingStep.

public Step getAtlasMappingStep(StepDefinition mapping, List<StepDefinition> precedingSteps, StepDefinition followingStep) {
    processPrecedingSteps(precedingSteps);
    processFolowingStep(followingStep);
    List<DataMapperStepDefinition> mappings = mapping.getDataMapperDefinition().get().getDataMapperStepDefinition();
    AtlasMapping atlasMapping = new AtlasMapping();
    atlasMapping.setMappings(new Mappings());
    for (DataSource s : processSources(precedingSteps)) {
        atlasMapping.getDataSource().add(s);
    }
    atlasMapping.setName("REST." + UUID.randomUUID().toString());
    atlasMapping.setLookupTables(new LookupTables());
    atlasMapping.setProperties(new Properties());
    atlasMapping.getDataSource().add(processTarget(followingStep));
    atlasMapping.getMappings().getMapping().addAll(generateBaseMappings(mappings, precedingSteps, followingStep));
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
    String mapperString = null;
    try {
        mapperString = mapper.writeValueAsString(atlasMapping);
        log.debug(mapperString);
    } catch (JsonProcessingException e) {
        log.error("error: {}" + e);
    }
    final Step mapperStep = new Step.Builder().stepKind(StepKind.mapper).configuredProperties(TestUtils.map("atlasmapping", mapperString)).action(getMapperStepAction(followingStep.getConnectorDescriptor().get())).id(UUID.randomUUID().toString()).build();
    return mapperStep;
}
Also used : DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTables(io.atlasmap.v2.LookupTables) Step(io.syndesis.common.model.integration.Step) Properties(io.atlasmap.v2.Properties) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 42 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method isJSONValid.

/**
 * @return true, if current JSON layout structure is valid
 */
protected boolean isJSONValid() {
    ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    ObjectReader reader = mapper.readerForUpdating(new JSONLayoutPage());
    try {
        String json = isWindows() ? m_textArea.getText() : m_jsonDocument;
        JSONLayoutPage page = reader.readValue(json);
        m_documentNodeIDs.clear();
        if (page.getRows() != null) {
            for (JSONLayoutRow row : page.getRows()) {
                populateDocumentNodeIDs(row);
            }
            compareNodeIDs();
        }
        return true;
    } catch (IOException | NumberFormatException e) {
        String errorMessage;
        if (e instanceof JsonProcessingException) {
            JsonProcessingException jsonException = (JsonProcessingException) e;
            Throwable cause = null;
            Throwable newCause = jsonException.getCause();
            while (newCause instanceof JsonProcessingException) {
                if (cause == newCause) {
                    break;
                }
                cause = newCause;
                newCause = cause.getCause();
            }
            if (cause instanceof JsonProcessingException) {
                jsonException = (JsonProcessingException) cause;
            }
            errorMessage = jsonException.getOriginalMessage().split("\n")[0];
            JsonLocation location = jsonException.getLocation();
            if (location != null) {
                errorMessage += " at line: " + (location.getLineNr() + 1) + " column: " + location.getColumnNr();
            }
        } else {
            String message = e.getMessage();
            errorMessage = message;
        }
        if (m_statusLine != null && !m_statusLine.isDisposed()) {
            m_statusLine.setForeground(new Color(Display.getCurrent(), 255, 0, 0));
            m_statusLine.setText(errorMessage);
            int textWidth = isWindows() ? m_textArea.getSize().width : m_text.getSize().x;
            Point newSize = m_statusLine.computeSize(textWidth, m_statusLine.getSize().y, true);
            m_statusLine.setSize(newSize);
        }
    }
    return false;
}
Also used : JsonLocation(com.fasterxml.jackson.core.JsonLocation) JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) Color(org.eclipse.swt.graphics.Color) IOException(java.io.IOException) Point(org.eclipse.swt.graphics.Point) JSONLayoutRow(org.knime.js.core.layout.bs.JSONLayoutRow) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 43 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project traccar by tananaev.

the class EventForwarder method prepareJsonPayload.

protected String prepareJsonPayload(Event event, Position position, Set<Long> users) {
    Map<String, Object> data = new HashMap<>();
    data.put(KEY_EVENT, event);
    if (position != null) {
        data.put(KEY_POSITION, position);
    }
    Device device = Context.getIdentityManager().getById(event.getDeviceId());
    if (device != null) {
        data.put(KEY_DEVICE, device);
    }
    if (event.getGeofenceId() != 0) {
        Geofence geofence = Context.getGeofenceManager().getById(event.getGeofenceId());
        if (geofence != null) {
            data.put(KEY_GEOFENCE, geofence);
        }
    }
    data.put(KEY_USERS, Context.getUsersManager().getItems(users));
    try {
        return Context.getObjectMapper().writeValueAsString(data);
    } catch (JsonProcessingException e) {
        Log.warning(e);
        return null;
    }
}
Also used : HashMap(java.util.HashMap) Device(org.traccar.model.Device) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Geofence(org.traccar.model.Geofence)

Example 44 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project traccar by tananaev.

the class CsvBuilder method addLine.

public void addLine(Object object) {
    SortedSet<Method> methods = getSortedMethods(object);
    for (Method method : methods) {
        if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
            try {
                if (method.getReturnType().equals(boolean.class)) {
                    builder.append(method.invoke(object));
                    addSeparator();
                } else if (method.getReturnType().equals(int.class)) {
                    builder.append(method.invoke(object));
                    addSeparator();
                } else if (method.getReturnType().equals(long.class)) {
                    builder.append(method.invoke(object));
                    addSeparator();
                } else if (method.getReturnType().equals(double.class)) {
                    builder.append(method.invoke(object));
                    addSeparator();
                } else if (method.getReturnType().equals(String.class)) {
                    builder.append((String) method.invoke(object));
                    addSeparator();
                } else if (method.getReturnType().equals(Date.class)) {
                    Date value = (Date) method.invoke(object);
                    builder.append(DATE_FORMAT.print(new DateTime(value)));
                    addSeparator();
                } else if (method.getReturnType().equals(Map.class)) {
                    Map value = (Map) method.invoke(object);
                    if (value != null) {
                        try {
                            String map = Context.getObjectMapper().writeValueAsString(value);
                            map = map.replaceAll("[\\{\\}\"]", "");
                            map = map.replaceAll(",", " ");
                            builder.append(map);
                            addSeparator();
                        } catch (JsonProcessingException e) {
                            Log.warning(e);
                        }
                    }
                }
            } catch (IllegalAccessException | InvocationTargetException error) {
                Log.warning(error);
            }
        }
    }
    addLineEnding();
}
Also used : Method(java.lang.reflect.Method) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Date(java.util.Date) DateTime(org.joda.time.DateTime) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 45 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project atlasmap by atlasmap.

the class GenerateInspectionsMojo method generateInspection.

private void generateInspection(List<String> artifacts, Collection<String> classNames) throws MojoFailureException, MojoExecutionException {
    List<URL> urls = artifacts == null ? Collections.emptyList() : resolveClasspath(artifacts);
    ClassLoader origTccl = Thread.currentThread().getContextClassLoader();
    for (String className : classNames) {
        Class<?> clazz = null;
        JavaClass c = null;
        // Not even this plugin will be available on this new URLClassLoader
        try (URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), origTccl)) {
            clazz = loader.loadClass(className);
            ClassInspectionService classInspectionService = new ClassInspectionService();
            classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
            c = classInspectionService.inspectClass(loader, clazz);
        } catch (ClassNotFoundException | IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        try {
            ObjectMapper objectMapper = Json.mapper();
            File target = outputFile;
            if (target == null) {
                target = new File(outputDir, "atlasmap-inpection-" + className + ".json");
            }
            objectMapper.writeValue(target, c);
            getLog().info("Created: " + target);
        } catch (JsonProcessingException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) URL(java.net.URL) JavaClass(io.atlasmap.java.v2.JavaClass) URLClassLoader(java.net.URLClassLoader) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) URLClassLoader(java.net.URLClassLoader) File(java.io.File) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)648 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)205 IOException (java.io.IOException)156 HashMap (java.util.HashMap)105 Map (java.util.Map)77 ArrayList (java.util.ArrayList)67 JsonNode (com.fasterxml.jackson.databind.JsonNode)54 List (java.util.List)50 Test (org.junit.Test)44 InputStream (java.io.InputStream)24 Collectors (java.util.stream.Collectors)24 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)23 Json (com.sequenceiq.cloudbreak.domain.json.Json)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 Function (java.util.function.Function)18 Test (org.testng.annotations.Test)18 File (java.io.File)17 Date (java.util.Date)17 UnsupportedEncodingException (java.io.UnsupportedEncodingException)15 URL (java.net.URL)15