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


Java ObjectWriter類代碼示例

本文整理匯總了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());
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:18,代碼來源:MessageRestControllerTest.java

示例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;
    }
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:24,代碼來源:NetworkStateExporter.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: 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);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:23,代碼來源:TestStandardObjectWriter.java

示例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;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:26,代碼來源:SyncClient.java

示例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);

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

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

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

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

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

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

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

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

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

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


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