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