当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.writeValueAsString方法代码示例

本文整理汇总了Java中org.codehaus.jackson.map.ObjectMapper.writeValueAsString方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.writeValueAsString方法的具体用法?Java ObjectMapper.writeValueAsString怎么用?Java ObjectMapper.writeValueAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jackson.map.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.writeValueAsString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testValidateResponseJsonErrorUnknownException

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testValidateResponseJsonErrorUnknownException()
    throws IOException {
  Map<String, Object> json = new HashMap<String, Object>();
  json.put(HttpExceptionUtils.ERROR_EXCEPTION_JSON, "FooException");
  json.put(HttpExceptionUtils.ERROR_CLASSNAME_JSON, "foo.FooException");
  json.put(HttpExceptionUtils.ERROR_MESSAGE_JSON, "EX");
  Map<String, Object> response = new HashMap<String, Object>();
  response.put(HttpExceptionUtils.ERROR_JSON, json);
  ObjectMapper jsonMapper = new ObjectMapper();
  String msg = jsonMapper.writeValueAsString(response);
  InputStream is = new ByteArrayInputStream(msg.getBytes());
  HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
  Mockito.when(conn.getErrorStream()).thenReturn(is);
  Mockito.when(conn.getResponseMessage()).thenReturn("msg");
  Mockito.when(conn.getResponseCode()).thenReturn(
      HttpURLConnection.HTTP_BAD_REQUEST);
  try {
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_CREATED);
    Assert.fail();
  } catch (IOException ex) {
    Assert.assertTrue(ex.getMessage().contains("EX"));
    Assert.assertTrue(ex.getMessage().contains("foo.FooException"));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestHttpExceptionUtils.java

示例2: testValidateResponseJsonErrorKnownException

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testValidateResponseJsonErrorKnownException() throws IOException {
  Map<String, Object> json = new HashMap<String, Object>();
  json.put(HttpExceptionUtils.ERROR_EXCEPTION_JSON, IllegalStateException.class.getSimpleName());
  json.put(HttpExceptionUtils.ERROR_CLASSNAME_JSON, IllegalStateException.class.getName());
  json.put(HttpExceptionUtils.ERROR_MESSAGE_JSON, "EX");
  Map<String, Object> response = new HashMap<String, Object>();
  response.put(HttpExceptionUtils.ERROR_JSON, json);
  ObjectMapper jsonMapper = new ObjectMapper();
  String msg = jsonMapper.writeValueAsString(response);
  InputStream is = new ByteArrayInputStream(msg.getBytes());
  HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
  Mockito.when(conn.getErrorStream()).thenReturn(is);
  Mockito.when(conn.getResponseMessage()).thenReturn("msg");
  Mockito.when(conn.getResponseCode()).thenReturn(
      HttpURLConnection.HTTP_BAD_REQUEST);
  try {
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_CREATED);
    Assert.fail();
  } catch (IllegalStateException ex) {
    Assert.assertEquals("EX", ex.getMessage());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestHttpExceptionUtils.java

示例3: signIn

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
public boolean signIn(String u, String p) {
	HttpHeaders headers = new HttpHeaders();
   	headers.setContentType(MediaType.APPLICATION_JSON);
	ObjectMapper mapper=ObjectMapperPool.getMapper();

	String json="";
	try {
		json = mapper.writeValueAsString(new LoginRequest(u, p, fingerPrint.getFingerPrint()));
	
		HttpEntity<String> entity = new HttpEntity<String>(json, headers);
		ResponseEntity<String> response=restTemplate.postForEntity(serverPath.concat(Constants.SIGN_IN_SUFFIX), entity, String.class);
		LoginResponse resp=mapper.readValue(response.getBody(), LoginResponse.class);
		logger.debug("Got login response {}",resp.getResult());
		return resp.getResult();
	} catch (Exception e) {
		logger.error("Parse exception", e);
	}
	return false;
}
 
开发者ID:zafar142007,项目名称:FolderSync,代码行数:21,代码来源:Auth.java

示例4: createNewUser

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
public boolean createNewUser(String u, String p) {
	HttpHeaders headers = new HttpHeaders();
   	headers.setContentType(MediaType.APPLICATION_JSON);
	ObjectMapper mapper=ObjectMapperPool.getMapper();

	String json="";
	try {
		json = mapper.writeValueAsString(new LoginRequest(u, p, fingerPrint.getFingerPrint()));
	
		HttpEntity<String> entity = new HttpEntity<String>(json, headers);
		ResponseEntity<String> response=restTemplate.postForEntity(serverPath.concat(Constants.CREATE_USER_SUFFIX), entity, String.class);
		CreateUserResponse resp=mapper.readValue(response.getBody(), CreateUserResponse.class);
		logger.debug("Got create user response {}",resp.getStatus());
		return resp.isResult();
	} catch (Exception e) {
		logger.error("Parse exception", e);
	}
	return false;
}
 
开发者ID:zafar142007,项目名称:FolderSync,代码行数:21,代码来源:Auth.java

示例5: getSchedulingDecisionSummary

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public String getSchedulingDecisionSummary() {
  Map<Object, Integer> decisions = scheduleCacheRef.get();
  if (decisions == null) {
    return "{}";
  } else {
    try {
      ObjectMapper om = new ObjectMapper();
      return om.writeValueAsString(decisions);
    } catch (Exception e) {
      return "Error: " + e.getMessage();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:DecayRpcScheduler.java

示例6: testSerialization

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testSerialization()
throws JsonGenerationException, JsonMappingException, IOException {
  PerformanceEvaluation.TestOptions options = new PerformanceEvaluation.TestOptions();
  assertTrue(!options.isAutoFlush());
  options.setAutoFlush(true);
  ObjectMapper mapper = new ObjectMapper();
  String optionsString = mapper.writeValueAsString(options);
  PerformanceEvaluation.TestOptions optionsDeserialized =
      mapper.readValue(optionsString, PerformanceEvaluation.TestOptions.class);
  assertTrue(optionsDeserialized.isAutoFlush());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:13,代码来源:TestPerformanceEvaluation.java

示例7: toJsonString

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public static String toJsonString(final List<XAttr> xAttrs, 
    final XAttrCodec encoding) throws IOException {
  final Map<String, Object> finalMap = new TreeMap<String, Object>();
  finalMap.put("XAttrs", toJsonArray(xAttrs, encoding));
  ObjectMapper mapper = new ObjectMapper();
  return mapper.writeValueAsString(finalMap);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:JsonUtil.java

示例8: generatePartialResourceRequest

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
private HttpEntity<MultiValueMap<String, ?>> generatePartialResourceRequest(UploadApplicationPayload application,
    CloudResources knownRemoteResources) throws IOException {
    MultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>(2);
    body.add("application", application);
    ObjectMapper mapper = new ObjectMapper();
    String knownRemoteResourcesPayload = mapper.writeValueAsString(knownRemoteResources);
    body.add("resources", knownRemoteResourcesPayload);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    return new HttpEntity<MultiValueMap<String, ?>>(body, headers);
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:12,代码来源:CloudControllerClientImpl.java

示例9: mapToJson

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
private static String mapToJson(Map map){
  ObjectMapper mapperObj = new ObjectMapper();
  String jsonResp = "";
  try {
    jsonResp = mapperObj.writeValueAsString(map);
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  return jsonResp;
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:12,代码来源:OrganisationControllerTest.java

示例10: getCallVolumeSummary

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public String getCallVolumeSummary() {
  try {
    ObjectMapper om = new ObjectMapper();
    return om.writeValueAsString(callCounts);
  } catch (Exception e) {
    return "Error: " + e.getMessage();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:9,代码来源:DecayRpcScheduler.java

示例11: getContentSummary

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
 * Return the JSON formatted ContentSummary of the specified path.
 * @param path a path specifies a file or directory
 * @return JSON formatted ContentSummary
 * @throws IOException if failed to serialize ContentSummary to JSON.
 */
String getContentSummary(String path) throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  return "{\"ContentSummary\":\n"
          + mapper.writeValueAsString(getContentSummaryMap(path)) + "\n}\n";
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:FSImageLoader.java


注:本文中的org.codehaus.jackson.map.ObjectMapper.writeValueAsString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。