本文整理匯總了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);
}