Package org.codehaus.jackson.map

Examples of org.codehaus.jackson.map.ObjectWriter


  {
    ObjectMapper mapper = new ObjectMapper();
    boolean pretty = request.getParams().getProperty("pretty") != null;
   
    // create pretty or regular writer
    ObjectWriter writer = pretty ? mapper.defaultPrettyPrintingWriter() : mapper.writer();
    StringWriter out = new StringWriter(10240);
   
    DbusEventBufferMult multBuf = _relay.getEventBuffer();
    Set<PhysicalPartitionKey> keys = multBuf.getAllPhysicalPartitionKeys();
    // creat map to output partId=>PhysicalSources...
    Map<PhysicalPartition, Set<PhysicalSource>> map =
        new HashMap<PhysicalPartition, Set<PhysicalSource>>(keys.size());
    for(PhysicalPartitionKey key: keys) {
      Set<PhysicalSource> set = multBuf.getPhysicalSourcesForPartition(key.getPhysicalPartition());
      map.put(key.getPhysicalPartition(), set);
    }
   
    if(keys.isEmpty()) {
      writer.writeValue(out, new HashSet<PhysicalPartition>());
    } else {
      writer.writeValue(out,map);
    }
   
    byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
   
    request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
View Full Code Here


        response.addHeader("Content-Disposition", "attachment; filename=backup.json");
        response.setContentType("application/json");

        Backup backup = BackupService.getInstance().getBackupData();
        ObjectMapper objectMapper = new ObjectMapper();
        ObjectWriter writer = objectMapper.defaultPrettyPrintingWriter();

        return writer.withView(ViewFilters.Default.class).writeValueAsString(backup);
    }
View Full Code Here

        if (data != null && !data.equals("") &&
                responseContentType != null && responseContentType.toLowerCase().indexOf("application/json") != -1) {
            // try to format it
            try {
                ObjectMapper objectMapper = new ObjectMapper();
                ObjectWriter writer = objectMapper.defaultPrettyPrintingWriter();
                Object json = objectMapper.readValue(data, Object.class);
                this.formattedResponseData = writer.withView(ViewFilters.Default.class).writeValueAsString(json);
            } catch (JsonParseException jpe) {
                // nothing to do here as this.formattedResponseData was already set to the appropriate data
            }
        }
    }
View Full Code Here

        if (originalResponseData != null && !originalResponseData.equals("") &&
                originalResponseContentType != null && originalResponseContentType.toLowerCase().indexOf("application/json") != -1) {
            try {
                // try to format it
                ObjectMapper objectMapper = new ObjectMapper();
                ObjectWriter writer = objectMapper.defaultPrettyPrintingWriter();
                Object json = objectMapper.readValue(originalResponseData, Object.class);
                this.formattedOriginalResponseData = writer.withView(ViewFilters.Default.class).writeValueAsString(json);
            } catch (JsonParseException jpe) {
                // nothing to do here as this.formattedResponseData was already set to the appropriate data
            }
        }
    }
View Full Code Here

    Reader input = new FileReader(inputFile);
    try {
      Writer output = new FileWriter(outputFile);
      try {
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
        Iterator<Map> i = mapper.readValues(
                new JsonFactory().createJsonParser(input), Map.class);
        while (i.hasNext()) {
          Map m = i.next();
          output.write(writer.writeValueAsString(createSLSJob(m)) + EOL);
        }
      } finally {
        output.close();
      }
    } finally {
View Full Code Here

  private static void generateSLSNodeFile(String outputFile)
          throws IOException {
    Writer output = new FileWriter(outputFile);
    try {
      ObjectMapper mapper = new ObjectMapper();
      ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
      for (Map.Entry<String, Set<String>> entry : rackNodeMap.entrySet()) {
        Map rack = new LinkedHashMap();
        rack.put("rack", entry.getKey());
        List nodes = new ArrayList();
        for (String name : entry.getValue()) {
          Map node = new LinkedHashMap();
          node.put("node", name);
          nodes.add(node);
        }
        rack.put("nodes", nodes);
        output.write(writer.writeValueAsString(rack) + EOL);
      }
    } finally {
      output.close();
    }
  }
View Full Code Here

  }

  private ObjectWriter getExceptionWriter(Exception e)
  {
    String name = e.getClass().getCanonicalName();
    ObjectWriter objectWriter = exceptionWriters.get(name);
    if (objectWriter == null)
    {
      initializeExceptionObjects(e, name);
    }
    return exceptionWriters.get(name);
View Full Code Here

  private void initializeExceptionObjects(Exception e, String name)
    {
      exceptionlock.lock();
      try
      {
        ObjectWriter objectWriter = exceptionWriters.get(name);
        if (objectWriter == null)
        {
          objectWriter = JsonUtil.createWriter(e.getClass());
          exceptionWriters.put(name, objectWriter);
          exceptionIds.put(name, hash(name));
View Full Code Here

  public static ObjectWriter createWriter(Type type)
  {
    ObjectMapper mapper = getObjectMapper(type);
    setGlobalConfigurations(mapper);
    JavaType paramJavaType = mapper.getTypeFactory().constructType(type);
    ObjectWriter writer = mapper.writerWithType(paramJavaType);
    return writer;
  }
View Full Code Here

    private String getSystemInfo() {
        try {
            SystemInfoManagerLocal mgr = LookupUtil.getSystemInfoManager();
            Map<String, String> systemInfo = mgr.getSystemInformation(LookupUtil.getSubjectManager().getOverlord());
            final ObjectWriter writer = new ObjectMapper().writerWithDefaultPrettyPrinter();
            return writer.writeValueAsString(systemInfo);
        }
        catch (Exception e) {
            log.error(e);
            return "ERROR retrieving system info : "+e.getMessage();
        }
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.map.ObjectWriter

Copyright © 2018 www.massapicom. 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.