當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。