本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectWriter.writeValue方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectWriter.writeValue方法的具体用法?Java ObjectWriter.writeValue怎么用?Java ObjectWriter.writeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectWriter
的用法示例。
在下文中一共展示了ObjectWriter.writeValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
public static void write(SecurityAnalysisResult result, Writer writer) throws IOException {
Objects.requireNonNull(result);
Objects.requireNonNull(writer);
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(SecurityAnalysisResult.class, new SecurityAnalysisResultSerializer());
module.addSerializer(NetworkMetadata.class, new NetworkMetadataSerializer());
module.addSerializer(PostContingencyResult.class, new PostContingencyResultSerializer());
module.addSerializer(LimitViolationsResult.class, new LimitViolationsResultSerializer());
module.addSerializer(LimitViolation.class, new LimitViolationSerializer());
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
objectMapper.registerModule(module);
ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
objectWriter.writeValue(writer, result);
}
示例2: write
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
private static void write(Contingency object, Path jsonFile) {
Objects.requireNonNull(object);
Objects.requireNonNull(jsonFile);
try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
mapper.registerModule(module);
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, object);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例3: saveProfile
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
public void saveProfile() throws IOException {
ObjectMapper mapper = new ObjectMapper();
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
ow.writeValue(new File(profileFileName), localClient().getProfile());
}
示例4: close
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
try {
final EncryptedDataContainer encrypted = cipher.doFinal();
super.write(encrypted.getContent());
final String tag = CryptoUtils.byteArrayToString(encrypted.getTag());
final ObjectReader reader = session.getClient().getJSON().getContext(null).readerFor(FileKey.class);
final FileKey fileKey = reader.readValue(status.getFilekey().array());
fileKey.setTag(tag);
final ObjectWriter writer = session.getClient().getJSON().getContext(null).writerFor(FileKey.class);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
writer.writeValue(out, fileKey);
status.setFilekey(ByteBuffer.wrap(out.toByteArray()));
}
catch(CryptoSystemException e) {
throw new IOException(e);
}
finally {
super.close();
}
}
示例5: pre
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
@Override
public Void pre(final Transfer.Type type, final Map<Path, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException {
try {
switch(type) {
case download:
break;
default:
if(session.userAccount().isEncryptionEnabled()) {
for(Map.Entry<Path, TransferStatus> entry : files.entrySet()) {
if(containerService.getContainer(entry.getKey()).getType().contains(Path.Type.vault)) {
final TransferStatus status = entry.getValue();
final FileKey fileKey = TripleCryptConverter.toSwaggerFileKey(Crypto.generateFileKey());
final ObjectWriter writer = session.getClient().getJSON().getContext(null).writerFor(FileKey.class);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
writer.writeValue(out, fileKey);
status.setFilekey(ByteBuffer.wrap(out.toByteArray()));
}
}
}
}
return null;
}
catch(IOException e) {
throw new DefaultIOExceptionMappingService().map(e);
}
}
示例6: encode
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
@Override
public void encode(OutputStream out, Object object) throws Exception {
Class<?> clazz = object.getClass();
JsonGenerator generator = constructGenerator(out);
JavaType type = mapper.getTypeFactory().constructType(clazz);
ObjectWriter writer = mapper.writerFor(type);
writer.writeValue(generator, object);
generator.close();
}
示例7: writeOutErrors
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
/**
* Write out the errors to a file.
*
* @param allErrors The errors to write.
* @param outFile The location to write.
*/
private void writeOutErrors(AllErrors allErrors, Path outFile) {
try (Writer writer = Files.newBufferedWriter(outFile)) {
ObjectWriter jsonObjectWriter = new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.writer()
.withDefaultPrettyPrinter();
jsonObjectWriter.writeValue(writer, allErrors);
} catch (IOException exception) {
DEV_LOG.error("Could not write out error JSON to file", exception);
}
}
示例8: write
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
public static void write(LoadFlowResult result, Path jsonFile) {
Objects.requireNonNull(result);
Objects.requireNonNull(jsonFile);
try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(LoadFlowResult.class, new LoadFlowResultSerializer());
objectMapper.registerModule(module);
ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, result);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例9: writeInternal
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
@Override
@SuppressWarnings("deprecation")
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
try {
JavaType javaType = null;
if (jackson26Available && type != null && object != null && TypeUtils.isAssignable(type, object.getClass())) {
javaType = getJavaType(type, null);
}
ObjectWriter objectWriter;
objectWriter = this.objectMapper.writer();
if (javaType != null && javaType.isContainerType()) {
objectWriter = objectWriter.withType(javaType);
}
objectWriter.writeValue(generator, object);
generator.flush();
}
catch (JsonProcessingException ex) {
throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
}
}
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:28,代码来源:AbstractJackson2HttpMessageConverter.java
示例10: setFileKey
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
private void setFileKey(final TransferStatus status) throws BackgroundException {
// copy between encrypted and unencrypted data room
final FileKey fileKey = TripleCryptConverter.toSwaggerFileKey(Crypto.generateFileKey());
final ObjectWriter writer = session.getClient().getJSON().getContext(null).writerFor(FileKey.class);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
writer.writeValue(out, fileKey);
}
catch(IOException e) {
throw new DefaultIOExceptionMappingService().map(e);
}
status.setFilekey(ByteBuffer.wrap(out.toByteArray()));
}
示例11: writeJsonMetric
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
/**
* serialize a JSON metric over the outputstream in a bulk request
*/
private void writeJsonMetric(JsonMetric jsonMetric, ObjectWriter writer, OutputStream out) throws IOException {
writer.writeValue(out, new BulkIndexOperationHeader(currentIndexName, jsonMetric.type()));
out.write("\n".getBytes());
writer.writeValue(out, jsonMetric);
out.write("\n".getBytes());
out.flush();
}
示例12: write
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
public static void write(ObjectWriter objectWriter, FileObject fileObject, Object object) {
try (Writer writer = fileObject.openWriter()) {
objectWriter.writeValue(writer, object);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例13: encode
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
@Override
public void encode(OutputStream out, Object object) throws Exception {
Class<?> clazz = object.getClass();
JsonGenerator generator = constructGenerator(out);
JavaType type = mapper.getTypeFactory().constructType(clazz);
ObjectWriter writer = mapper.writerFor(type);
writer.writeValue(generator, object);
generator.flush();
generator.close();
}
示例14: writeObjectToFile
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
protected void writeObjectToFile(final ObjectWriter objectWriter, final Object object, final File targetFile)
throws IOException {
targetFile.getParentFile().mkdirs();
targetFile.createNewFile();
objectWriter.writeValue(targetFile, object);
}