本文整理汇总了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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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 "{}";
}
}
示例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 "";
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
}