当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.writeValue方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.writeValue方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.writeValue方法的具体用法?Java ObjectMapper.writeValue怎么用?Java ObjectMapper.writeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.writeValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateConfig

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
void updateConfig() throws IOException {
    // we assume we only get called in the root directory of a project
    if (!Files.exists(EADL_CONFIG)) {
        printNotInitialized();
        return;
    } else if (!Files.isWritable(EADL_CONFIG)) {
        CLI.println("Could not write config file, please check permissions.");
        return;
    }
    ObjectMapper mapper = new ObjectMapper();
    try {
        mapper.writeValue(EADL_CONFIG.toFile(), config);
    } catch (IOException e) {
        LOG.error("Error writing eadl config to file.", e);
    }
}
 
开发者ID:adr,项目名称:eadlsync,代码行数:17,代码来源:EADLSyncCommand.java

示例2: objectToString

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static String objectToString (final Object object) {
    if (object == null) {
        return null;
    }

    try {
        final StringWriter stringWriter = new StringWriter();

        final ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        objectMapper.writeValue(stringWriter, object);

        return stringWriter.toString().replaceAll(System.getProperty("line.separator"), "");
    } catch (IOException ex) {
        STRINGUTIL_LOGGER.info("Sorry. had a error on during Object to String. ("+ex.toString()+")");
        return null;
    }
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:20,代码来源:StringObjectUtils.java

示例3: readYAMLFile

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void readYAMLFile() {

    // new error-free endpoint
    Endpoint endpoint = resources.createEndpoint("GET", "/test-yaml-file", "200");

    // write yaml file on temporary directory
    ObjectMapper mapperJson = new ObjectMapper(new YAMLFactory());
    File file = TempIO.buildFile("read-yaml-file", ".lyre", resources.getDirectory(0));

    try {
        mapperJson.writeValue(file, endpoint);
    } catch (IOException e) {
        fail("Couldn't write on temporary file: " + e.getMessage());
    }

    reader.read(file);

    //should have a object node with yaml file on it.
    assertThat(reader.getObjectNodes()).isNotEmpty();
    assertThat(reader.getObjectNodes().get(file.getAbsolutePath())).isNotNull();

}
 
开发者ID:groovylabs,项目名称:lyre,代码行数:24,代码来源:ReaderTest.java

示例4: testSerialize

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testSerialize() throws Exception {
    String expected = "{\"version\":null,\"status\":0,\"routeInstructions\":null,\"routeGeometry\":[[50.753,5.712],[50.653,6.012]]}";
    GeoCoordinates[] coords = new GeoCoordinates[2];
    coords[0] = new GeoCoordinates(50.753, 5.712);
    coords[1] = new GeoCoordinates(50.653, 6.012);
    PathData pathData = new PathData.Builder().withRouteGeometry(coords).build();

    ObjectMapper mapper = new ObjectMapper();
    mapper.addMixInAnnotations(PathData.class, UraPathDataMixIn.class);
    Writer stringWriter = new StringWriter();
    try {
        mapper.writeValue(stringWriter, pathData);
        String json = stringWriter.toString();
        assertNotNull(json);
        assertEquals(json, expected);
    } catch (Exception e) {
        fail();
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:21,代码来源:UraSerializerWrapperTest.java

示例5: artifact

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public SummaryResponse artifact(List<String> checksums, List<String> paths) throws IOException {
    if (checksums == null && paths == null) {
        return new SummaryResponseImpl();
    }

    ObjectMapper mapper = ObjectMapperHelper.get();
    ArtifactSummaryBody summaryBody = new ArtifactSummaryBody(checksums, paths);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    mapper.writeValue(out, summaryBody);
    ByteArrayInputStream content = new ByteArrayInputStream(out.toByteArray());

    Map<String, String> headers = new HashMap<>();
    XrayImpl.addContentTypeJsonHeader(headers);

    HttpResponse response = xray.post("summary/artifact", headers, content);
    return mapper.readValue(response.getEntity().getContent(), SummaryResponseImpl.class);
}
 
开发者ID:JFrogDev,项目名称:jfrog-idea-plugin,代码行数:19,代码来源:SummaryImpl.java

示例6: verifySuccess

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void verifySuccess() throws Exception {
    final Principal principalWritten = new DefaultPrincipalFactory().createPrincipal("casuser");

    final ObjectMapper mapper = new ObjectMapper();
    final StringWriter writer = new StringWriter();
    mapper.writeValue(writer, principalWritten);
    
    server.andRespond(withSuccess(writer.toString(), MediaType.APPLICATION_JSON));

    final HandlerResult res = authenticationHandler.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
    assertEquals(res.getPrincipal().getId(), "casuser");
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:14,代码来源:RestAuthenticationHandlerTests.java

示例7: dataToJson

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static String dataToJson(Object data) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        StringWriter sw = new StringWriter();
        mapper.writeValue(sw, data);
        return sw.toString();
    }
    catch (IOException e) {
        throw new RuntimeException("IOException while mapping object (" + data + ") to JSON");
    }
}
 
开发者ID:Joklost,项目名称:datalog-parser,代码行数:13,代码来源:JsonUtil.java

示例8: toString

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static String toString(TrainingDataModel model)
    throws JsonGenerationException, JsonMappingException, IOException {
  ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  objectMapper.setSerializationInclusion(Include.NON_NULL);
  StringWriter sw = new StringWriter();
  objectMapper.writeValue(sw, model);
  return sw.toString();
}
 
开发者ID:osswangxining,项目名称:conversationinsights-service,代码行数:10,代码来源:TrainingDataProcessor.java

示例9: writeToFile

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void writeToFile(String jsonOutputFile,Object gson){
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    try {
        mapper.writeValue(new File(jsonOutputFile), gson);
        System.out.println("Generated: "+ jsonOutputFile);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        throw new RuntimeException(e.toString());
    }

}
 
开发者ID:IBM,项目名称:janusgraph-utils,代码行数:13,代码来源:GSONUtil.java

示例10: writeToFile

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void writeToFile(String jsonOutputFile,Object gson){
    ObjectMapper mapper = new ObjectMapper();
    try {
        mapper.writeValue(new File(jsonOutputFile), gson);
        System.out.println("Generated: "+ jsonOutputFile);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        throw new RuntimeException(e.toString());
    } 

}
 
开发者ID:tedhtchang,项目名称:JanusGraphBench,代码行数:12,代码来源:GSONUtil.java

示例11: toString

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static String toString(Object object) {
	StringWriter sw = new StringWriter();
	ObjectMapper mapper = new ObjectMapper();
	mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
	try {
		mapper.writeValue(sw, object);
	} catch (IOException e) {
		log.error("Object to Json error", e);
	}
	return sw.toString();
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:12,代码来源:JsonUtils.java

示例12: generateEdgeLine

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void generateEdgeLine(StringWriter sw, ObjectMapper mapper, EdgeBean eBean) throws JsonGenerationException, JsonMappingException, IOException {
    sw.getBuffer().setLength(0);
    
    sw.append('E'); // Record type
    sw.append('=');
    
    mapper.writeValue(sw, eBean);
    
    sw.append('#');
    
    int hashCode = sw.toString().hashCode(); 
    sw.append(toHex(hashCode));
    sw.append('\n');
}
 
开发者ID:lambdazen,项目名称:bitsy,代码行数:15,代码来源:Record.java

示例13: publishMetricFilters

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public int publishMetricFilters(Collection<MetricFilter> metricFilters) {
    log.info("Writing metric filters to output file: " + outputFile.getPath());
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    try {
        mapper.writeValue(outputFile, metricFilters);
    } catch (IOException e) {
        log.error("Error writing JSON to output file.", e);
    }
    return 0;
}
 
开发者ID:symphoniacloud,项目名称:lambda-monitoring,代码行数:13,代码来源:GenerateMetricFilterPublisher.java

示例14: saveAccounts

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public void saveAccounts(List<Account> accounts) {
    try {
        final ObjectMapper mapper = new ObjectMapper()
                .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
        System.out.println(mapper.writeValueAsString(accounts));
        mapper.writeValue(rulesFile, accounts);
    } catch (IOException ex) {
        Logger.getLogger(AccountService.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:11,代码来源:AccountService.java

示例15: writeDataToFile

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void writeDataToFile() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    File recordFile = getRecordFile(testName);
    recordFile.createNewFile();
    mapper.writeValue(recordFile, recordedData);
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:8,代码来源:InterceptorManager.java


注:本文中的com.fasterxml.jackson.databind.ObjectMapper.writeValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。