当前位置: 首页>>代码示例>>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;未经允许,请勿转载。