Java 类org.codehaus.jackson.map.ObjectWriter 实例源码

项目:hadoop    文件:RumenToSLSConverter.java   
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  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 {
    input.close();
  }
}
项目:hadoop    文件:RumenToSLSConverter.java   
@SuppressWarnings("unchecked")
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();
  }
}
项目:aliyun-oss-hadoop-fs    文件:RumenToSLSConverter.java   
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  try (Reader input =
      new InputStreamReader(new FileInputStream(inputFile), "UTF-8")) {
    try (Writer output =
        new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
      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);
      }
    }
  }
}
项目:aliyun-oss-hadoop-fs    文件:RumenToSLSConverter.java   
@SuppressWarnings("unchecked")
private static void generateSLSNodeFile(String outputFile)
        throws IOException {
  try (Writer output =
      new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
    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);
    }
  }
}
项目:big-c    文件:RumenToSLSConverter.java   
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  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 {
    input.close();
  }
}
项目:big-c    文件:RumenToSLSConverter.java   
@SuppressWarnings("unchecked")
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();
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:RumenToSLSConverter.java   
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  Reader input = new FileReader(inputFile);
  try {
    Writer output = new FileWriter(outputFile);
    try {
      ObjectMapper mapper = new ObjectMapper();
      ObjectWriter writer = mapper.defaultPrettyPrintingWriter();
      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 {
    input.close();
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:RumenToSLSConverter.java   
@SuppressWarnings("unchecked")
private static void generateSLSNodeFile(String outputFile)
        throws IOException {
  Writer output = new FileWriter(outputFile);
  try {
    ObjectMapper mapper = new ObjectMapper();
    ObjectWriter writer = mapper.defaultPrettyPrintingWriter();
    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();
  }
}
项目:onboard    文件:RedisPublisher.java   
private void broadcastByActivity(User owner, Activity activity, BaseProjectItem originalItem, BaseProjectItem updatedItem)
        throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);
    ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter();
    activity.setSubscribers(userService.getUserByProjectId(activity.getProjectId()));
    activity.setAttachObject((BaseProjectItem)identifiableManager.getIdentifiableByTypeAndId(activity.getAttachType(),
            activity.getAttachId()));
    String message = "";
    try {
        message = ow.writeValueAsString(activity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    template.convertAndSend("channel", message);
}
项目:montgomery    文件:NewsEntryResource.java   
@GET
@Produces(MediaType.APPLICATION_JSON)
public String list() throws JsonGenerationException, JsonMappingException,
        IOException {
    this.logger.info("list()");

    ObjectWriter viewWriter;
    if (this.isAdmin()) {
        viewWriter = this.mapper.writerWithView(JsonViews.Admin.class);
    } else {
        viewWriter = this.mapper.writerWithView(JsonViews.User.class);
    }
    List<NewsEntry> allEntries = this.newsEntryDao.findAll();

    return viewWriter.writeValueAsString(allEntries);
}
项目:artifactory    文件:JsonUtil.java   
/**
 * jsonToString exclude null data end edit fields
 *
 * @param model - model data to String
 * @return - model data with json format
 */
public static String jsonToStringIgnoreSpecialFields(RestModel model) {
    String[] ExcludedFieldsFromView = getExcludedFields(model);
    ObjectMapper specialMapper = new ObjectMapper();
    specialMapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
    String data = null;
    FilterProvider filters = new SimpleFilterProvider()
            .addFilter("exclude fields",
                    SimpleBeanPropertyFilter.serializeAllExcept(
                            (ExcludedFieldsFromView)));
    ObjectWriter writer = specialMapper.writer(filters);
    try {
        data = writer.writeValueAsString(model);
    } catch (IOException e) {
        log.debug(e.getMessage());
    }
    return data;
}
项目:hops    文件:RumenToSLSConverter.java   
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  Reader input = new FileReader(inputFile);
  try {
    Writer output = new FileWriter(outputFile);
    try {
      ObjectMapper mapper = new ObjectMapper();
      ObjectWriter writer = mapper.defaultPrettyPrintingWriter();
      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 {
    input.close();
  }
}
项目:hops    文件:RumenToSLSConverter.java   
@SuppressWarnings("unchecked")
private static void generateSLSNodeFile(String outputFile)
        throws IOException {
  Writer output = new FileWriter(outputFile);
  try {
    ObjectMapper mapper = new ObjectMapper();
    ObjectWriter writer = mapper.defaultPrettyPrintingWriter();
    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();
  }
}
项目:hops    文件:RumenToSLSConverter.java   
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  try (Reader input =
      new InputStreamReader(new FileInputStream(inputFile), "UTF-8")) {
    try (Writer output =
        new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
      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);
      }
    }
  }
}
项目:hops    文件:RumenToSLSConverter.java   
@SuppressWarnings("unchecked")
private static void generateSLSNodeFile(String outputFile)
        throws IOException {
  try (Writer output =
      new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
    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);
    }
  }
}
项目:switchyard    文件:JSONJacksonSerializer.java   
/**
 * {@inheritDoc}
 */
@Override
public <T> int serialize(T obj, Class<T> type, OutputStream out) throws IOException {
    out = new CountingOutputStream(new BufferedOutputStream(out, getBufferSize()));
    try {
        ObjectWriter writer = _objectMapper.writerWithType(type);
        if (isPrettyPrint()) {
            writer = writer.withDefaultPrettyPrinter();
        }
        writer.writeValue(out, obj);
    } finally {
        if (isCloseEnabled()) {
            out.close();
        }
    }
    return ((CountingOutputStream)out).getCount();
}
项目:helix    文件:StateTransitionThrottleConfig.java   
/**
 * Generate the JSON String for StateTransitionThrottleConfig.
 *
 * @return Json String for this config.
 */
public String toJSON() {
  Map<String, String> configMap = new HashMap<String, String>();
  configMap.put(ConfigProperty.REBALANCE_TYPE.name(), _rebalanceType.name());
  configMap.put(ConfigProperty.THROTTLE_SCOPE.name(), _throttleScope.name());
  configMap.put(ConfigProperty.MAX_PARTITION_IN_TRANSITION.name(),
      String.valueOf(_maxPartitionInTransition));

  String jsonStr = null;
  try {
    ObjectWriter objectWriter = OBJECT_MAPPER.writer();
    jsonStr = objectWriter.writeValueAsString(configMap);
  } catch (IOException e) {
    logger.error("Failed to convert config map to JSON object! " + configMap);
  }

  return jsonStr;
}
项目:basiclti-util-java    文件:LTI2Servlet.java   
protected void getToolConsumerProfile(HttpServletRequest request,
        HttpServletResponse response,String profile_id)
{
    // Map<String,Object> deploy = ltiService.getDeployForConsumerKeyDao(profile_id);
    Map<String,Object> deploy = null;

    ToolConsumer consumer = buildToolConsumerProfile(request, deploy, profile_id);

    ObjectMapper mapper = new ObjectMapper();
    try {
        // http://stackoverflow.com/questions/6176881/how-do-i-make-jackson-pretty-print-the-json-content-it-generates
        ObjectWriter writer = mapper.defaultPrettyPrintingWriter();
        // ***IMPORTANT!!!*** for Jackson 2.x use the line below instead of the one above:
        // ObjectWriter writer = mapper.writer().withDefaultPrettyPrinter();
        // System.out.println(mapper.writeValueAsString(consumer));
        response.setContentType(APPLICATION_JSON);
        PrintWriter out = response.getWriter();
        out.println(writer.writeValueAsString(consumer));
        // System.out.println(writer.writeValueAsString(consumer));
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
项目:jersey-angular    文件:NewsEntryResource.java   
@GET
@Produces(MediaType.APPLICATION_JSON)
public String list() throws JsonGenerationException, JsonMappingException, IOException
{
    this.logger.info("list()");

    ObjectWriter viewWriter;
    if (this.isAdmin()) {
        viewWriter = this.mapper.writerWithView(JsonViews.Admin.class);
    } else {
        viewWriter = this.mapper.writerWithView(JsonViews.User.class);
    }
    List<NewsEntry> allEntries = this.newsEntryDao.findAll();

    return viewWriter.writeValueAsString(allEntries);
}
项目:montgomery    文件:NewsEntryResource.java   
@GET
@Produces(MediaType.APPLICATION_JSON)
public String list() throws JsonGenerationException, JsonMappingException,
        IOException {
    this.logger.info("list()");

    ObjectWriter viewWriter;
    if (this.isAdmin()) {
        viewWriter = this.mapper.writerWithView(JsonViews.Admin.class);
    } else {
        viewWriter = this.mapper.writerWithView(JsonViews.User.class);
    }
    List<NewsEntry> allEntries = this.newsEntryDao.findAll();

    return viewWriter.writeValueAsString(allEntries);
}
项目:hadoop-on-lustre2    文件:RumenToSLSConverter.java   
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  Reader input = new FileReader(inputFile);
  try {
    Writer output = new FileWriter(outputFile);
    try {
      ObjectMapper mapper = new ObjectMapper();
      ObjectWriter writer = mapper.defaultPrettyPrintingWriter();
      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 {
    input.close();
  }
}
项目:hadoop-on-lustre2    文件:RumenToSLSConverter.java   
@SuppressWarnings("unchecked")
private static void generateSLSNodeFile(String outputFile)
        throws IOException {
  Writer output = new FileWriter(outputFile);
  try {
    ObjectMapper mapper = new ObjectMapper();
    ObjectWriter writer = mapper.defaultPrettyPrintingWriter();
    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();
  }
}
项目:cananolab    文件:ViewFilterUtil.java   
/**
 * Get an inclusive jackson object writer for writing a set of named fields of an object
 * 
 * @param includeFieldNames fields that should be serialized    
 * @param filterName filter name. This needs to match the @JsonFilter("filterName") annotation for a bean
 * 
 * @return a Jackson ObjectWriter
 * @throws Exception
 */
public static ObjectWriter getInclusiveObjectWriter(String[] includeFieldNames, String filterName) 
throws Exception {

    if (includeFieldNames == null)
        throw new Exception("includeFieldNames can't be null");

    if (filterName == null)
        throw new Exception("filterName can't be null");

    ObjectMapper mapper = new ObjectMapper();  
    FilterProvider filters = new SimpleFilterProvider()  
      .addFilter(filterName,   
          SimpleBeanPropertyFilter.filterOutAllExcept(includeFieldNames));  
    return mapper.writer(filters);  

}
项目:cananolab    文件:ViewFilterUtil.java   
/**
 * Get an exclusive jackson object writer for serializing an object without a set of named fields
 * 
 * @param excludeFieldNames fields that should be excluded for serialization
 * @param filterName filter name. This needs to match the @JsonFilter("filterName") annotation for a bean
 * 
 * @return a Jackson ObjectWriter
 * @throws Exception
 */
public static ObjectWriter getExclusivObjectWriter(String[] excludeFieldNames, String filterName) 
        throws Exception {
    if (excludeFieldNames == null)
        throw new Exception("includeFieldNames can't be null");

    if (filterName == null)
        throw new Exception("filterName can't be null");

    ObjectMapper mapper = new ObjectMapper();  
    FilterProvider filters = new SimpleFilterProvider()  
      .addFilter(filterName,   
          SimpleBeanPropertyFilter.serializeAllExcept(excludeFieldNames));  
    return mapper.writer(filters);  

}
项目:memorise    文件:MemoEntryResource.java   
@GET
@Produces(MediaType.APPLICATION_JSON)
public String list() throws JsonGenerationException, JsonMappingException, IOException {
    this.logger.info("list()");

    ObjectWriter viewWriter;
    if (this.isPublisher()) {
        viewWriter = this.mapper.writerWithView(JsonViews.Publisher.class);
    } else {
        viewWriter = this.mapper.writerWithView(JsonViews.User.class);
    }
    List<Memo> allEntries = this.basicMemoService.findAll();

    return viewWriter.writeValueAsString(allEntries);
}
项目:azkaban    文件:JSONUtils.java   
public static String toJSON(Object obj, boolean prettyPrint) {
  ObjectMapper mapper = new ObjectMapper();

  try {
    if (prettyPrint) {
      ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
      return writer.writeValueAsString(obj);
    }
    return mapper.writeValueAsString(obj);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
项目:azkaban    文件:JSONUtils.java   
public static void toJSON(Object obj, OutputStream stream, boolean prettyPrint) {
  ObjectMapper mapper = new ObjectMapper();
  try {
    if (prettyPrint) {
      ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
      writer.writeValue(stream, obj);
      return;
    }
    mapper.writeValue(stream, obj);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
项目:apex-core    文件:StringCodec.java   
@Override
public String toString(T pojo)
{
  try {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    ObjectWriter writer = mapper.writer();
    return writer.writeValueAsString(pojo);
  } catch (IOException e) {
    throw Throwables.propagate(e);
  }
}
项目:apex-malhar    文件:ZKAssistedDiscovery.java   
JacksonInstanceSerializer(ObjectReader objectReader, ObjectWriter objectWriter,
    TypeReference<ServiceInstance<T>> typeRef)
{
  this.objectReader = objectReader;
  this.objectWriter = objectWriter;
  this.typeRef = typeRef;
}
项目:Megh    文件:ZKAssistedDiscovery.java   
JacksonInstanceSerializer(ObjectReader objectReader, ObjectWriter objectWriter,
    TypeReference<ServiceInstance<T>> typeRef)
{
  this.objectReader = objectReader;
  this.objectWriter = objectWriter;
  this.typeRef = typeRef;
}
项目:musicFinder    文件:SearchUtil.java   
public static String convertSongListToJSON(Set<SongVO> listOfSong,String query) throws JsonGenerationException, JsonMappingException, IOException{
    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
    String json="";
    json = ow.writeValueAsString(listOfSong);
    return "{"+"\""+query+"\":"+json+"}";

}
项目:onboard    文件:WebSocketServiceImpl.java   
/**
 * 根据map生成json
 * 
 * @param actionMap
 * @return
 */
private String getJson(Object activity) {
    ObjectMapper objectMapper = new ObjectMapper();

    objectMapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);
    ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter();
    String message = "";
    try {
        message = ow.writeValueAsString(activity);
    } catch (IOException e) {
        logger.info("activity to json failure");
    }
    return message;
}
项目:azkaban-customization    文件:JSONUtils.java   
public static String toJSON(Object obj, boolean prettyPrint) {
    ObjectMapper mapper = new ObjectMapper();

    try {
        if (prettyPrint) {
            ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
            return writer.writeValueAsString(obj);
        }
        return mapper.writeValueAsString(obj);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:azkaban-customization    文件:JSONUtils.java   
public static void toJSON(Object obj, OutputStream stream, boolean prettyPrint) {
    ObjectMapper mapper = new ObjectMapper();
    try {
        if (prettyPrint) {
            ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
            writer.writeValue(stream, obj);
            return;
        }
        mapper.writeValue(stream, obj);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:cs-244-project    文件:CryptoUtil.java   
public static Digest computeDigest(Object value) {
    if (NO_CRYPTO) return new Digest(new byte[10]);
    try {
        ObjectWriter writer = mapper.writer();
        MessageDigest digest = MessageDigest.getInstance(DIGEST_TYPE);
        return new Digest(digest.digest(writer.writeValueAsString(value).getBytes()));
    } catch (NoSuchAlgorithmException | IOException e) {
        e.printStackTrace();
    }

    return null;
}
项目:cs-244-project    文件:CryptoUtil.java   
public static byte[] convertToJsonByteArray(Object message) {
    ObjectWriter writer = mapper.writer(FIELD_FILTER);
    try {
        return writer.writeValueAsString(message).getBytes();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
项目:archived-net-virt-platform    文件:LogMessageDocProcessor.java   
protected void processLogMessage(LogMessageDoc m, Element element) {
    Element encElement = element.getEnclosingElement();
    LogMessageCategory category = 
            element.getAnnotation(LogMessageCategory.class);
    if (category == null)
        category = encElement.getAnnotation(LogMessageCategory.class);

    String categoryStr = "Core";
    if (category != null) categoryStr = category.value();

    LogMessageDocItemData lmdi = new LogMessageDocItemData();
    lmdi.className = encElement.asType().toString();
    lmdi.category = categoryStr;
    lmdi.severity = m.level();
    lmdi.message = m.message();
    lmdi.explanation = m.explanation();
    lmdi.recommendation = m.recommendation();

    ObjectMapper mapper = new ObjectMapper();
    ObjectWriter writer = mapper.defaultPrettyPrintingWriter();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        writer.writeValue(os, lmdi);
        out.print(os.toString());
        out.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
项目:jscompiler    文件:ASTTestGeneratorMain.java   
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
    String pattern = FileUtils.readFileToString(new File(PATTERN));
    String input = FileUtils.readFileToString(new File(INPUT_FILE));
    ObjectMapper objMapper = new ObjectMapper();
    String[] tokens = input.split("###");
    int i = 1;
    StringBuilder sb = new StringBuilder();
    for (String js : tokens) {
        if (js.trim().length() == 0) {
            continue;
        }
        System.out.println("Test " + i + " of " + tokens.length);
        Parser parser = new Parser(js.trim());
        ASTRoot root = parser.parse();
        ObjectWriter writer = objMapper.defaultPrettyPrintingWriter();
        String json = writer.writeValueAsString(root);
        FileUtils.write(new File(new File(OUTPUT_FOLDER),
                "ast_expected_" + i + ".json"), json);
        sb.append(pattern.replace("@@", i + "").replace("###", escapeQuote(js.trim())));
        i++;
    }
    FileUtils.writeStringToFile(
            new File(new File(OUTPUT_FOLDER), "out.txt"), 
            sb.toString());

}
项目:jscompiler    文件:ParserTest.java   
public void testBase(String js, String fileName) 
        throws JsonGenerationException, JsonMappingException, IOException, JSONException {
    Parser parser = new Parser(js);
    ASTRoot root = parser.parse();

    ObjectMapper objMapper = new ObjectMapper();
    ObjectWriter writer = objMapper.defaultPrettyPrintingWriter();
    String actual = writer.writeValueAsString(root);
    JSONAssert.assertEquals(getJson(fileName), actual, false);
}
项目:jscompiler    文件:ParserTest.java   
@Test
public void test_0() 
        throws JsonGenerationException, JsonMappingException, IOException {
    String js = " function filip(a,b,c,d) {if (a == 5 / c * 54 && a/4==f*3 || ff!=5) {}}";
    Parser parser = new Parser(js);
    ASTRoot root = parser.parse();

    ObjectWriter writer = objMapper.defaultPrettyPrintingWriter();
}