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


Java ObjectMapper.setDateFormat方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.ObjectMapper.setDateFormat方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectMapper.setDateFormat方法的具體用法?Java ObjectMapper.setDateFormat怎麽用?Java ObjectMapper.setDateFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.setDateFormat方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: jsonListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonListSerialization(List<Record> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:14,代碼來源:Record.java

示例2: jsonSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Serialize all the class attributes
 * @return
 * @throws Exception 
 */
public JsonNode jsonSerialization() throws Exception
{
    JsonNode jsonError;
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat);       
    jsonError = mapper.convertValue(this, JsonNode.class);
    return jsonError;
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:15,代碼來源:Person.java

示例3: jsonSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Serialize a list of objects with a particular set of attributes
 * @param view
 * @return
 * @throws IOException 
 */
public JsonNode jsonSerialization(Class view) throws IOException
{
    ObjectMapper mapper = new ObjectMapper();
    
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    mapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
    
    ObjectWriter writer = mapper.writerWithView(view);
    JsonNode response = mapper.readTree(writer.writeValueAsString(this));
    return response;
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:19,代碼來源:Record.java

示例4: jsonSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Serialize all the class attributes
 * @return
 * @throws Exception 
 */
@Override
public JsonNode jsonSerialization() throws Exception
{
    JsonNode jsonError;
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat);       
    jsonError = mapper.convertValue(this, JsonNode.class);
    return jsonError;
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:16,代碼來源:Instructor.java

示例5: jsonStudentsListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonStudentsListSerialization(List<Student> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:14,代碼來源:Student.java

示例6: jsonDesSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Des-Serialize an object who was in json format
 * @param jsonObject
 * @return
 * @throws Exception 
 */
public static CourseSession jsonDesSerialization(JsonNode jsonObject) throws Exception
{
    CourseSession object;
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    object = mapper.convertValue(jsonObject,CourseSession.class);
    return object;
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:17,代碼來源:CourseSession.java

示例7: jsonInstructorsListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonInstructorsListSerialization(List<Instructor> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:14,代碼來源:Instructor.java

示例8: buildObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Create and configure the {@link ObjectMapper} used for serializing and deserializing
 * JSON requests and responses.
 *
 * @return a configured {@link ObjectMapper}
 */
public static ObjectMapper buildObjectMapper() {
	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.setDateFormat(new ISO8601DateFormat());
	objectMapper.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy());
	objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
	objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	objectMapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
	objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);

	configureCredentialDetailTypeMapping(objectMapper);

	return objectMapper;
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:20,代碼來源:JsonUtils.java

示例9: jsonListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonListSerialization(List<Role> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:15,代碼來源:Role.java

示例10: jsonDesSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Des-Serialize an object who was in json format
 * @param jsonObject
 * @return
 * @throws Exception 
 */
public static Allocation jsonDesSerialization(JsonNode jsonObject) throws Exception
{
    Allocation object;
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    object = mapper.convertValue(jsonObject,Allocation.class);
    return object;
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:17,代碼來源:Allocation.java

示例11: jsonDesSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Des-Serialize an object who was in json format
 * @param jsonObject
 * @return
 * @throws Exception 
 */
public static Course jsonDesSerialization(JsonNode jsonObject) throws Exception
{
    Course object;
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    object = mapper.convertValue(jsonObject,Course.class);
    return object;
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:17,代碼來源:Course.java

示例12: jsonListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonListSerialization(List<Allocation> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:14,代碼來源:Allocation.java

示例13: verifyJsonToPdxInstanceConversion

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
private void verifyJsonToPdxInstanceConversion() {
  TestObjectForJSONFormatter expectedTestObject = new TestObjectForJSONFormatter();
  expectedTestObject.defaultInitialization();
  Cache c = CacheFactory.getAnyInstance();
  Region region = c.getRegion("primitiveKVStore");

  // 1.gets pdxInstance using R.put() and R.get()
  region.put("501", expectedTestObject);
  Object receivedObject = region.get("501");
  if (receivedObject instanceof PdxInstance) {
    PdxInstance expectedPI = (PdxInstance) receivedObject;

    // 2. Get the JSON string from actualTestObject using jackson ObjectMapper.
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    String json;
    try {
      json = objectMapper.writeValueAsString(expectedTestObject);

      String jsonWithClassType = expectedTestObject.addClassTypeToJson(json);

      // 3. Get PdxInstance from the Json String and Validate pi.getObject() API.
      PdxInstance actualPI = JSONFormatter.fromJSON(jsonWithClassType);
      // Note: expectedPI will contains those fields that are part of toData()
      // expectedPI.className = "org.apache.geode.pdx.TestObjectForJSONFormatter"
      // actualPI will contains all the fields that are member of the class.
      // actualPI..className = __GEMFIRE_JSON
      // and hence actualPI.equals(expectedPI) will returns false.

      Object actualTestObject = actualPI.getObject();

      if (actualTestObject instanceof TestObjectForJSONFormatter) {
        boolean isObjectEqual = actualTestObject.equals(expectedTestObject);
        Assert.assertTrue(isObjectEqual,
            "actualTestObject and expectedTestObject should be equal");
      } else {
        fail("actualTestObject is expected to be of type PdxInstance");
      }
    } catch (JsonProcessingException e1) {
      fail("JsonProcessingException occurred:" + e1.getMessage());
    } catch (JSONException e) {
      fail("JSONException occurred:" + e.getMessage());
    }
  } else {
    fail("receivedObject is expected to be of type PdxInstance");
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:50,代碼來源:JSONFormatterJUnitTest.java


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