当前位置: 首页>>代码示例>>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;未经允许,请勿转载。