Search in sources :

Example 66 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project BIMserver by opensourceBIM.

the class GenerateGeometryLibrary method generate.

private void generate(EPackage ePackage, Schema schema) {
    this.ePackage = ePackage;
    packageMetaData = new PackageMetaData(ePackage, schema, Paths.get("tmp"));
    rootNode = OBJECT_MAPPER.createObjectNode();
    definesNode = OBJECT_MAPPER.createObjectNode();
    rootNode.set("defines", definesNode);
    process((EClass) ePackage.getEClassifier("IfcShapeRepresentation"), (EClass) ePackage.getEClassifier("IfcRepresentation"));
    // cleanup();
    try {
        Files.write(OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsBytes(rootNode), new File("C:\\Users\\Ruben de Laat\\git\\BIMserver\\BimServer\\src\\org\\bimserver\\database\\queries\\json\\" + schema.name().toLowerCase() + "-geometry.json"));
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : PackageMetaData(org.bimserver.emf.PackageMetaData) IOException(java.io.IOException) File(java.io.File) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 67 with JsonProcessingException

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

the class Application method main.

public static void main(String[] args) throws IOException {
    System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory");
    System.setProperty("hsqldb.reconfig_logging", "false");
    ApplicationContext applicationContext = SwaggerApp.Run(SpringConfig.class);
    Application application = new Application();
    application.demo(applicationContext);
    final ObjectMapper objectMapper = applicationContext.getBean(ObjectMapper.class);
    final Router router = applicationContext.getBean(Router.class);
    router.route().failureHandler(frc -> {
        /**
         * 任一请求出错都会进入到这里
         */
        int statusCode = frc.statusCode();
        HttpServerResponse response = frc.response();
        response.putHeader("content-type", "application/json;charset=UTF-8");
        Map<String, String> map = new HashMap<>();
        map.put("error", "Sorry! Not today");
        map.put("status", String.valueOf(statusCode));
        map.put("path", frc.request().path());
        map.put("msg", frc.failure() == null ? "" : frc.failure().getMessage());
        String rs = "{}";
        try {
            rs = objectMapper.writeValueAsString(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        response.setStatusCode(statusCode).end(rs);
    });
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) HashMap(java.util.HashMap) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Router(io.vertx.ext.web.Router) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 68 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project FarmCloud by vratsasg.

the class EmbeddedController method getAllDevicesWateringTime.

@RequestMapping(value = "endDevicesTime", method = RequestMethod.GET)
public ResponseEntity<String> getAllDevicesWateringTime(@RequestParam("identifier") String coordinator) {
    String JsonResults = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        List<EmebddedSetupDevicdeDto> ls = featureofInterestService.findEndDevicesTimes(coordinator);
        JsonResults = mapper.writeValueAsString(ls);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
    } catch (Exception e) {
        e.printStackTrace();
        return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
    }
    return new ResponseEntity<String>(JsonResults, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 69 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project FarmCloud by vratsasg.

the class FeatureofInterestServiceImpl method findMinMaxbyUserId.

public String findMinMaxbyUserId(Integer userid) {
    String jsonInString = null;
    try {
        List<FeatureObsPropMinMax> results = featureofinterestJpaRepository.findFeatureMiMaxValuesByUserId(userid);
        List<FeatureObsProp> featureobsPropList = new ArrayList<FeatureObsProp>();
        featureobsPropList.add(new FeatureObsProp(results.get(0).getFeatureofinterestid(), results.get(0).getIdentifier(), results.get(0).getName()));
        for (FeatureObsPropMinMax obj : results) {
            boolean newaddition = true;
            for (int i = 0; i < featureobsPropList.size(); i++) {
                FeatureObsProp feature = featureobsPropList.get(i);
                if (obj.getFeatureofinterestid() == feature.getFeatureofinterestid()) {
                    newaddition = false;
                }
            }
            if (newaddition) {
                featureobsPropList.add(new FeatureObsProp(obj.getFeatureofinterestid(), obj.getIdentifier(), obj.getName()));
            }
        }
        for (FeatureObsPropMinMax obj : results) {
            for (FeatureObsProp feature : featureobsPropList) {
                if (obj.getFeatureofinterestid() == feature.getFeatureofinterestid()) {
                    feature.getFeatureObsproplist().add(new FeatureMinMaxValue((obj.getObspropvalId()).longValue(), obj.getObspropertName(), obj.getMinval(), obj.getMaxval()));
                }
            }
        }
        // Object to JSON in String
        ObjectMapper mapper = new ObjectMapper();
        jsonInString = mapper.writeValueAsString(featureobsPropList);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    return jsonInString;
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 70 with JsonProcessingException

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

the class TransactionalMessageCopier method toJsonString.

private static String toJsonString(Map<String, Object> data) {
    String json;
    try {
        ObjectMapper mapper = new ObjectMapper();
        json = mapper.writeValueAsString(data);
    } catch (JsonProcessingException e) {
        json = "Bad data can't be written as json: " + e.getMessage();
    }
    return json;
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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