本文整理汇总了Java中org.codehaus.jackson.map.ObjectWriter类的典型用法代码示例。如果您正苦于以下问题:Java ObjectWriter类的具体用法?Java ObjectWriter怎么用?Java ObjectWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectWriter类属于org.codehaus.jackson.map包,在下文中一共展示了ObjectWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSLSLoadFile
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
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();
}
}
示例2: generateSLSNodeFile
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
@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();
}
}
示例3: generateSLSLoadFile
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
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);
}
}
}
}
示例4: generateSLSNodeFile
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
@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);
}
}
}
示例5: generateSLSLoadFile
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
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();
}
}
示例6: generateSLSNodeFile
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
@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();
}
}
示例7: broadcastByActivity
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
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);
}
示例8: list
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
@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);
}
示例9: jsonToStringIgnoreSpecialFields
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
/**
* 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;
}
示例10: serialize
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
/**
* {@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();
}
示例11: toJSON
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
/**
* 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;
}
示例12: getToolConsumerProfile
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
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();
}
}
示例13: list
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
@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);
}
示例14: getInclusiveObjectWriter
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
/**
* 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);
}
示例15: getExclusivObjectWriter
import org.codehaus.jackson.map.ObjectWriter; //导入依赖的package包/类
/**
* 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);
}