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


Java ObjectMapper.writeValueAsString方法代码示例

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


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

示例1: getJsonSchema

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public String getJsonSchema() {
	ObjectMapper mapper = new ObjectMapper();
	try {
		mapper.enable(SerializationFeature.INDENT_OUTPUT);
		return mapper.writeValueAsString(jsonSchema);
	} catch (JsonProcessingException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:10,代码来源:BodyRaml.java

示例2: convertToString

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * convert Object into String.
 * @param obj Object
 * @return String
 */
public static String convertToString(Object obj) {
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        return objectMapper.writeValueAsString(obj);
    } catch (JsonProcessingException e) {
        log.error("JsonProcessingException while converting Entity into string", e);
    }
    return null;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:15,代码来源:ObjectMapperUtil.java

示例3: testSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testSerialization() throws IOException {
	ObjectMapper mapper = new ObjectMapper();
	mapper.registerModule(JacksonModule.createJacksonModule());

	ErrorDataBuilder builder = new ErrorDataBuilder();
	builder.setAboutLink("about");
	builder.setCode("code");
	builder.setDetail("detail");
	builder.setId("id");
	builder.setSourcePointer("sourcePointer");
	builder.setSourceParameter("sourceParameter");
	builder.setStatus("status");
	builder.setTitle("title");
	builder.addMetaField("meta1", "value1");

	ErrorData errorData = builder.build();
	String json = mapper.writeValueAsString(errorData);
	ErrorData copy = mapper.readerFor(ErrorData.class).readValue(json);

	Assert.assertEquals(errorData, copy);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:23,代码来源:ErrorDataTest.java

示例4: validate

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void validate(FieldTransformationBase e)
    throws JsonProcessingException, IOException, JsonParseException, JsonMappingException {
  ObjectMapper om = JSONUtil.mapper();
  String value = om.writeValueAsString(e);
  FieldTransformationBase readValue = om.readValue(value, FieldTransformationBase.class);
  assertEquals(e, readValue);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:8,代码来源:TestFieldTransformationBase.java

示例5: handleCustomOptions

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Handles getting custom defined options and values.
 * @param messageFormatForm The submitted form.
 */
private String handleCustomOptions(final MessageFormatForm messageFormatForm) {
    // Build a map of Name => Value
    final Map<String, String> mappedOptions = messageFormatForm.getCustomOptionsAsMap();

    // For converting map to json string
    final ObjectMapper objectMapper = new ObjectMapper();

    try {
        return objectMapper.writeValueAsString(mappedOptions);
    } catch (final JsonProcessingException e) {
        // Fail safe?
        return "{}";
    }
}
 
开发者ID:SourceLabOrg,项目名称:kafka-webview,代码行数:19,代码来源:MessageFormatController.java

示例6: managerAppoint

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@RequestMapping(value = "/appoint",method = RequestMethod.GET,produces = "text/html;charset=utf8")
@ResponseBody
public String managerAppoint(@RequestParam("roleid")Integer roleid,@RequestParam("uid") String uid){
    int i = roleid;
    if(3 < i && i < 10){
        List<Customer> list = customerService.queryAll();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(list);
        } catch (JsonProcessingException e) {
            return "";
        }
    }else {
        return "";
    }
}
 
开发者ID:zxbangban,项目名称:zxbangban,代码行数:17,代码来源:MyAccountController.java

示例7: getPayload

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
@SneakyThrows
public String getPayload() {

    Map<String, Object> likeMap = new LinkedHashMap<>();
    likeMap.put("_uuid", api.getUuid());
    likeMap.put("_uid", api.getUserId());
    likeMap.put("id", api.getUserId());
    likeMap.put("_csrftoken", api.getOrFetchCsrf(null));
    likeMap.put("experiment", "ig_android_profile_contextual_feed");

    ObjectMapper mapper = new ObjectMapper();
    String payloadJson = mapper.writeValueAsString(likeMap);

    return payloadJson;
}
 
开发者ID:charlieAndroidDev,项目名称:Instagram4Android,代码行数:17,代码来源:InstagramExposeRequest.java

示例8: toJson

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private String toJson(final Object object) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    String jsonRep = "";
    jsonRep = mapper.writeValueAsString(object);
    return jsonRep;
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:8,代码来源:RealAdapterTestLocalOnly.java

示例9: getPayload

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
@SneakyThrows
public String getPayload() {
    
    Map<String, Object> likeMap = new LinkedHashMap<>();
    likeMap.put("_uuid", api.getUuid());
    likeMap.put("_uid", api.getUserId());
    likeMap.put("user_id", userId);
    likeMap.put("_csrftoken", api.getOrFetchCsrf());
    
    ObjectMapper mapper = new ObjectMapper();
    String payloadJson = mapper.writeValueAsString(likeMap);

    return payloadJson;
}
 
开发者ID:brunocvcunha,项目名称:instagram4j,代码行数:16,代码来源:InstagramUnblockRequest.java

示例10: getPayload

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
@SneakyThrows
public String getPayload() {
    
    Map<String, Object> likeMap = new LinkedHashMap<>();
    likeMap.put("_uuid", api.getUuid());
    likeMap.put("_uid", api.getUserId());
    likeMap.put("_csrftoken", api.getOrFetchCsrf());
    likeMap.put("media_id", mediaId);
    
    ObjectMapper mapper = new ObjectMapper();
    String payloadJson = mapper.writeValueAsString(likeMap);

    return payloadJson;
}
 
开发者ID:brunocvcunha,项目名称:instagram4j,代码行数:16,代码来源:InstagramUnlikeRequest.java

示例11: getPayload

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
@SneakyThrows
public String getPayload() {

    Map<String, Object> likeMap = new LinkedHashMap<>();
    likeMap.put("_uuid", api.getUuid());
    likeMap.put("_uid", api.getUserId());
    likeMap.put("user_id", userId);
    likeMap.put("_csrftoken", api.getOrFetchCsrf(null));

    ObjectMapper mapper = new ObjectMapper();
    String payloadJson = mapper.writeValueAsString(likeMap);

    return payloadJson;
}
 
开发者ID:charlieAndroidDev,项目名称:Instagram4Android,代码行数:16,代码来源:InstagramUnfollowRequest.java

示例12: getErrorCode

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@ExceptionHandler(CerebroException.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public String getErrorCode(final CerebroException exception) throws IOException {
    LOGGER.error("Service error", exception);
    ObjectMapper objectMapper = new ObjectMapper();
    FilterProvider filterProvider = new SimpleFilterProvider().addFilter("responseFilter",
        SimpleBeanPropertyFilter.filterOutAllExcept("errorCode", "errorMessage"));
    objectMapper.setFilterProvider(filterProvider);
    return objectMapper.writeValueAsString(exception);
}
 
开发者ID:voyages-sncf-technologies,项目名称:cerebro,代码行数:11,代码来源:CerebroController.java

示例13: toString

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public String toString() {
	ObjectMapper objectMapper = AppLoader.getInstance(ObjectMapper.class);
	try {
		return objectMapper.writeValueAsString(this);
	} catch (JsonProcessingException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:10,代码来源:JsonOptions.java

示例14: toJSON

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Convert this object to json
 *
 * @return the json
 */
public String toJSON() {
    String returnVar = "";
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new Hibernate5Module());
    objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);

    try {
        returnVar = objectMapper.writeValueAsString(this);
    } catch (JsonProcessingException ex) {
        logger.info("[DataObject] [toJson] Convert Object To JSON Failure", ex);
    }

    return returnVar;
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:20,代码来源:DataObject.java

示例15: encode

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public String encode(DataAndInfo object) throws EncodeException {
    ObjectMapper mapper = (ObjectMapper) config.getUserProperties().get("mapper");
    try {
        return mapper.writeValueAsString(object);
    } catch (JsonProcessingException e) {
        throw new EncodeException(object, "JSON error", e);
    }
}
 
开发者ID:etomica,项目名称:etomica,代码行数:10,代码来源:DataStreamWebsocket.java


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