本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectWriter.writeValueAsString方法的具体用法?Java ObjectWriter.writeValueAsString怎么用?Java ObjectWriter.writeValueAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectWriter
的用法示例。
在下文中一共展示了ObjectWriter.writeValueAsString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBadRegistration
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
@Test
public void testBadRegistration() throws Exception {
RegisterDTO registerDTO = new RegisterDTO();
registerDTO.setUsername("JonkiPro");
registerDTO.setEmail("[email protected]");
registerDTO.setPassword("password1");
registerDTO.setPasswordAgain("password1");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
String requestJson = ow.writeValueAsString(registerDTO);
mockMvc
.perform(post("/api/v1.0/register")
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.content(requestJson))
.andExpect(status().isBadRequest());
}
示例2: 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);
}
}
示例3: toString
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
@Override
public String toString() {
try {
//转换为json字符串
ObjectWriter ow = new ObjectMapper().writer();//.withDefaultPrettyPrinter()
String json = ow.writeValueAsString(this);
return json;
} catch (JsonProcessingException e) {
return "";
}
}
示例4: 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 "";
}
示例5: toString
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
@Override
public String toString() {
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
return ow.writeValueAsString(this);
} catch (JsonProcessingException e) {
return "Could Not Marshal Object to JSON";
}
}
示例6: save
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
public void save(String key, Object object) {
ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String jsonString = objectWriter.writeValueAsString(object);
preferences.edit().putString(key, jsonString).apply();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
示例7: getString
import com.fasterxml.jackson.databind.ObjectWriter; //导入方法依赖的package包/类
private String getString(VolumeResource volumeResource, ObjectMapper mapper) throws JsonProcessingException {
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
return ow.writeValueAsString(volumeResource);
}