當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectWriter.writeValueAsString方法代碼示例

本文整理匯總了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());
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:20,代碼來源:RegisterRestControllerTest.java

示例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);
    }
}
 
開發者ID:limberest,項目名稱:limberest,代碼行數:18,代碼來源:JsonNodeService.java

示例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 "";
    }
}
 
開發者ID:Huawei,項目名稱:Server_Management_Plugin_vRealize,代碼行數:12,代碼來源:ServerDeviceBean.java

示例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 "";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:JacksonParserFactory.java

示例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";
    }
}
 
開發者ID:level11data,項目名稱:databricks-client-java,代碼行數:10,代碼來源:ClustersDTO.java

示例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();
        }


    }
 
開發者ID:bojanb89pa,項目名稱:OAuth2Android,代碼行數:13,代碼來源:DataCachingManager.java

示例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);
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:6,代碼來源:VolumeControllerTestIT.java


注:本文中的com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。