本文整理匯總了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);
}