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