本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.writer方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.writer方法的具体用法?Java ObjectMapper.writer怎么用?Java ObjectMapper.writer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.writer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getText
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public String getText(JsonNode jsonNode, int prettyIndent) throws ServiceException {
ObjectMapper mapper = new ObjectMapper();
try {
ObjectWriter writer;
if (prettyIndent > 0)
writer = mapper.writer(new JacksonPrettyPrinter(prettyIndent));
else
writer = mapper.writer();
return writer.writeValueAsString(jsonNode);
}
catch (JsonProcessingException ex) {
throw new ServiceException(Status.INTERNAL_ERROR, ex.getMessage(), ex);
}
}
示例2: getWriter
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
protected ObjectWriter getWriter(Format format, int prettyIndent) {
ObjectMapper mapper = getMapper(format);
if (prettyIndent > 0)
return mapper.writer(new JacksonPrettyPrinter(prettyIndent));
else
return mapper.writer();
}
示例3: SnsListener
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
SnsListener(AmazonSNSAsyncClient sns, ListenerConfig config, Clock clock) {
this.clock = clock;
LOG.info("Starting listener, topics: start={}, success={}, fail={}", config.getStartTopic(),
config.getSuccessTopic(), config.getFailTopic());
this.sns = sns;
this.config = config;
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
startWriter = mapper.writer();
}
示例4: testMapper
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testMapper() throws Exception {
final ObjectMapper objectMapper = objectMapperProvider.getContext(null);
final Blah value = new Blah();
value.setHello("abc");
final ObjectWriter writer = objectMapper.writer();
final String str = writer.writeValueAsString(value);
final Blah value2 = objectMapper.readerFor(Blah.class).readValue(str);
assertEquals(value.getHello(), value2.getHello());
}
示例5: JacksonSerializer
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public JacksonSerializer(ObjectMapper mapper, Class<X> clazz){
this.reader = mapper.reader(clazz);
this.writer = mapper.writer();
}
示例6: Json
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private Json(ObjectMapper mapper) {
this.mapper = mapper;
this.writer = mapper.writer();
this.prettyWriter = mapper.writerWithDefaultPrettyPrinter();
}
示例7: JacksonSerializer
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public JacksonSerializer(final ObjectMapper mapper, final Class<T> klazz) {
this.reader = mapper.readerFor(klazz);
this.writer = mapper.writer();
}
示例8: createObjectWriter
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static ObjectWriter createObjectWriter(ObjectMapper objectMapper, boolean prettyPrintEnabled) {
ObjectWriter objectWriter = prettyPrintEnabled
? objectMapper.writerWithDefaultPrettyPrinter()
: objectMapper.writer();
return objectWriter.withoutFeatures(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
}