本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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");
}
}