本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectWriter类的典型用法代码示例。如果您正苦于以下问题:Java ObjectWriter类的具体用法?Java ObjectWriter怎么用?Java ObjectWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectWriter类属于com.fasterxml.jackson.databind包,在下文中一共展示了ObjectWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBadSendMessage
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
@Test
public void testBadSendMessage() throws Exception {
SendMessageDTO message = new SendMessageDTO();
message.setTo("JonkiPro2");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
String requestJson = ow.writeValueAsString(message);
mockMvc
.perform(post("/api/v1.0/messages/")
.with(user(USERNAME).password(PASSWORD).roles(ROLE))
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.content(requestJson))
.andExpect(status().isBadRequest());
}
示例2: exportStatus
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
public boolean exportStatus(String outputFile) {
Repository frozenRepository = this.repository.getSnapshotTo(this.repository.getRoot());
File dumpFile = new File(outputFile);
try(FileWriter fw = new FileWriter(dumpFile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw)) {
JsonNodeFactory jsonFactory = new JsonNodeFactory(false);
ObjectNode mainNode = jsonFactory.objectNode();
for (ByteArrayWrapper address : frozenRepository.getAccountsKeys()) {
if(!address.equals(new ByteArrayWrapper(ZERO_BYTE_ARRAY))) {
mainNode.set(Hex.toHexString(address.getData()), createAccountNode(mainNode, address.getData(), frozenRepository));
}
}
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
bw.write(writer.writeValueAsString(mainNode));
return true;
} catch (IOException e) {
logger.error(e.getMessage(), e);
panicProcessor.panic("dumpstate", e.getMessage());
return false;
}
}
示例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: testWriteValueOutputStreamObject
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
@Test
public void testWriteValueOutputStreamObject() {
boolean status = true;
String[] stringArray = new String[1];
stringArray[0] = "abc";
new MockUp<ObjectWriter>() {
@Mock
public void writeValue(OutputStream out,
Object value) throws IOException, JsonGenerationException, JsonMappingException {
}
};
try {
StandardObjectWriter.writeValue(outputStream,
stringArray);
} catch (IOException e) {
status = false;
}
Assert.assertTrue(status);
}
示例5: execute
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
@Override
public boolean execute(String[] tokens, String line) throws Exception {
if (tokens.length < 2) {
err.println("Usage: " + syntaxString());
return false;
}
if (!checkStoreSettings()) return false;
StringReader sr = new StringReader(line);
while (sr.read() != ' ');
JsonParser jp = mjf.createParser(sr);
JsonNode keyNode = validateJson(jp);
if (keyNode == null) return false;
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
out.println("Deleting Key:");
out.println(writer.writeValueAsString(keyNode));
out.println("");
storeClient.delete(keyNode);
out.println("Success");
return false;
}
示例6: 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);
}
示例7: 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();
}
}
示例8: getText
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的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);
}
}
示例9: 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);
}
}
示例10: getConfiguration
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
@Override
public String getConfiguration() {
try {
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
return writer.writeValueAsString(currentConfig);
} catch (JsonProcessingException e) {
logger.error("Error writing configuration to string", e);
return e.toString();
}
}
示例11: writeEmptyHostJsonFile
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
protected void writeEmptyHostJsonFile(final ObjectWriter objectWriter) throws IOException {
info("");
info(SAVE_HOST_JSON);
final File hostJsonFile = Paths.get(getDeploymentStageDirectory(), HOST_JSON).toFile();
writeObjectToFile(objectWriter, new Object(), hostJsonFile);
info(SAVE_SUCCESS + hostJsonFile.getAbsolutePath());
}
示例12: getStringMap
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
@Override
public HashMap<String, String> getStringMap(Object object) {
try {
TypeReference<HashMap<String, String>> typeRef
= new TypeReference<HashMap<String, String>>() {
};
ObjectWriter objectWriter = mapper.writerFor(object.getClass());
return mapper.readValue(objectWriter.writeValueAsString(object), typeRef);
} catch (Exception e) {
e.printStackTrace();
}
return new HashMap<>();
}
示例13: testJSONGeneratorConfigured
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
@Test
public void testJSONGeneratorConfigured() throws IOException {
JSONPrettyPrintFilter filter = new JSONPrettyPrintFilter();
ContainerRequest request = ContainerRequestBuilder.from("http://localhost/foo/bar?pretty", "GET").accept("random/media").build();
ContainerResponse response = new ContainerResponse(request, Response.ok().build());
filter.filter(request, response);
ObjectWriterModifier modifier = ObjectWriterInjector.get();
assertNotNull(modifier);
JsonGenerator g = mock(JsonGenerator.class);
modifier.modify(mock(JsonEndpointConfig.class), new MultivaluedHashMap<String, Object>(), new Object(), mock(ObjectWriter.class), g);
verify(g).useDefaultPrettyPrinter();
}
示例14: requestBodyConverter
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectWriter writer = mapper.writerFor(javaType);
return new JacksonRequestBodyConverter<>(writer);
}
示例15: getString
import com.fasterxml.jackson.databind.ObjectWriter; //导入依赖的package包/类
@Override
public String getString(Object object) {
try {
ObjectWriter objectWriter = mapper.writerFor(object.getClass());
return objectWriter.writeValueAsString(object);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}