當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。