當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectWriter.writeValue方法代碼示例

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

}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:19,代碼來源:SecurityAnalysisResultSerializer.java

示例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);
    }
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:17,代碼來源:ContingencyJsonTest.java

示例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());
}
 
開發者ID:ripreal,項目名稱:V8LogScanner,代碼行數:6,代碼來源:ClientsManager.java

示例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();
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:22,代碼來源:CryptoOutputStream.java

示例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);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:27,代碼來源:SDSEncryptionBulkFeature.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:Jackson2AfterBurnCodec.java

示例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);
	}
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:18,代碼來源:ConversionFileWriterWrapper.java

示例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);
    }
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:16,代碼來源:LoadFlowResultSerializer.java

示例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()));
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:14,代碼來源:SDSDelegatingCopyFeature.java

示例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();
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:12,代碼來源:ElasticsearchReporter.java

示例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);
    }
}
 
開發者ID:Cosium,項目名稱:openapi-annotation-processor,代碼行數:8,代碼來源:SwaggerUtils.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:Jackson2Codec.java

示例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);
}
 
開發者ID:Microsoft,項目名稱:azure-maven-plugins,代碼行數:7,代碼來源:PackageMojo.java


注:本文中的com.fasterxml.jackson.databind.ObjectWriter.writeValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。