Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper.writeValue()


        HttpURLConnection connection = openConnection("messages/out/");
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        ObjectMapper mapper = new ObjectMapper();
        OutputStream out = connection.getOutputStream();
        mapper.writeValue(out, sms);
        out.close();
        connection.connect();
        int statusCode = connection.getResponseCode();
        if (statusCode == 200) {
            // Contact cannot receive message based on criteria (blocked or no matching subscription if supplied)
View Full Code Here


      if (!streamResponse) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
        JsonGenerator jsonGenerator = objectMapper.getFactory().createGenerator(bos, JsonEncoding.UTF8);

        if (jsonView == null) {
          objectMapper.writeValue(jsonGenerator, responseObject);
        } else {
          objectMapper.writerWithView(jsonView).writeValue(jsonGenerator, responseObject);
        }

        response.setContentLength(bos.size());
View Full Code Here

        jsonGenerator.close();
      } else {
        JsonGenerator jsonGenerator = objectMapper.getFactory()
            .createGenerator(outputStream, JsonEncoding.UTF8);
        if (jsonView == null) {
          objectMapper.writeValue(jsonGenerator, responseObject);
        } else {
          objectMapper.writerWithView(jsonView).writeValue(jsonGenerator, responseObject);
        }
        jsonGenerator.close();
      }
View Full Code Here

        // to construct a configuration only to get a simple value.
        ObjectMapper mapper = new JsonProvider(true)
            .locateMapper(Object.class, MediaType.APPLICATION_JSON_TYPE);
        FileWriter jsonFile = new FileWriter(apiFile);
        try {
            mapper.writeValue(jsonFile, allApiCalls);
        }
        finally {
            jsonFile.close();
        }
    }
View Full Code Here

    Map<String, List<Map<String, ?>>> map = (Map<String, List<Map<String, ?>>>) jsonSlurper.parseText(line);
    List<Map<String, ?>> statuses = map.get("statuses");
    for (Map<String, ?> tweet : statuses) {
      StringWriter sw = new StringWriter();
      try {
        mapper.writeValue(sw, tweet);
        sendMessage(MessageBuilder.withPayload(sw.toString()).build());
      }
      catch (JsonGenerationException ex) {
        logger.error("Failed to convert tweet to json: " + ex.getMessage());
        break;
View Full Code Here

      fileWriter = new FileWriter(gitPropsFile);
      if ("json".equalsIgnoreCase(format)) {
        log("Writing json file to [", gitPropsFile.getAbsolutePath(), "] (for module ", project.getName() + (++counter), ")...");
        ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(fileWriter, properties);
      } else {
        log("Writing properties file to [", gitPropsFile.getAbsolutePath(), "] (for module ", project.getName() + (++counter), ")...");
        properties.store(fileWriter, "Generated by Git-Commit-Id-Plugin");
      }
View Full Code Here

public class Jsons {
    public static String toJson(Object value) {
        ObjectMapper mapper = new ObjectMapper();
        StringWriter writer = new StringWriter();
        try {
            mapper.writeValue(writer, value);
            return writer.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

            } else {
                resp.setContentType("application/json");
                mapper = jsonMapper;
            }
            resp.setStatus(200);
            mapper.writeValue(resp.getNIOOutputStream(), result);           
        } catch (Exception ex) {
            resp.setStatus(500);
            resp.setContentType("text/plain");
            resp.getNIOWriter().write("Error: " + ex.toString());
        }
View Full Code Here

                //StringWriter wr = new StringWriter();
                ObjectMapper mapper = new ObjectMapper();
                JsonGenerator jsonGenerator = mapper.getJsonFactory().createJsonGenerator(out);
                //jsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter());
               
                mapper.writeValue(jsonGenerator, annotations.asMap());
                out.println(";");

                //writer.println(wr.toString());
            } catch (IOException ex) {
                java.util.logging.Logger.getLogger(AnnotationsToHTML.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

            rootNode.put("height", r.getHeight());
            rootNode.put("dwtLevels", r.getDWTLevels());
            rootNode.put("levels", r.getLevels());
            rootNode.put("compositingLayerCount", r.getCompositingLayerCount());

            mapper.writeValue(baos, rootNode);
        } catch (final DjatokaException e) {
            responseFormat = "text/plain";
            status = HttpServletResponse.SC_NOT_FOUND;
        } catch (final Exception e) {
            baos = new ByteArrayOutputStream();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.