• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DateDeserializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer的典型用法代码示例。如果您正苦于以下问题:Java DateDeserializer类的具体用法?Java DateDeserializer怎么用?Java DateDeserializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DateDeserializer类属于com.fasterxml.jackson.databind.deser.std.DateDeserializers包,在下文中一共展示了DateDeserializer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: deserialize

import com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer; //导入依赖的package包/类
@Override
public Date deserialize(final JsonParser parser, final DeserializationContext context) throws IOException
{
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");

    final String date = parser.getText();
    try
    {
        return formatter.parse(date);
    }
    catch (final ParseException ex)
    {
        // Not worked, so let the default date serializer give it a try.
        return DateDeserializer.instance.deserialize(parser, context);
    }
}
 
开发者ID:SevenSpikes,项目名称:shopify-api-java-wrapper,代码行数:17,代码来源:FlexDateDeserializer.java


示例2: deserialize

import com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Object deserialize(String json, String containerType, @SuppressWarnings("rawtypes") Class cls) throws ApiException {
    try{
      ObjectMapper mapper = JsonUtil.getJsonMapper();
	  SimpleModule m = new SimpleModule(PACKAGE_NAME, Version.unknownVersion());
	  m.addDeserializer(Date.class, new CustomDateDeserializer(new DateDeserializer()));
	  mapper.registerModule(m);
      
      if("List".equals(containerType)) {
        JavaType typeInfo = mapper.getTypeFactory().constructCollectionType(List.class, cls);
        List<?> response = (List<?>) mapper.readValue(json, typeInfo);
        return response;
      }
      else if(String.class.equals(cls)) {
        return json;
      }
      else {
        return mapper.readValue(json, cls);
      }
    }
    catch (IOException e) {
      throw new ApiException(500, e.getMessage());
    }
  }
 
开发者ID:liosha2007,项目名称:temporary-groupdocs-java-sdk,代码行数:25,代码来源:ApiInvoker.java


示例3: deserialize

import com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer; //导入依赖的package包/类
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
  try{
    ObjectMapper mapper = JsonUtil.getJsonMapper();
 SimpleModule m = new SimpleModule(PACKAGE_NAME, Version.unknownVersion());
 m.addDeserializer(Date.class, new CustomDateDeserializer(new DateDeserializer()));
 mapper.registerModule(m);
    
    if("List".equals(containerType)) {
      JavaType typeInfo = mapper.getTypeFactory().constructCollectionType(List.class, cls);
      List response = (List<?>) mapper.readValue(json, typeInfo);
      return response;
    }
    else if(String.class.equals(cls)) {
      return json;
    }
    else {
      return mapper.readValue(json, cls);
    }
  }
  catch (IOException e) {
    throw new ApiException(500, e.getMessage());
  }
}
 
开发者ID:uservidya,项目名称:groupdocs-java,代码行数:24,代码来源:ApiInvoker.java


示例4: deserialize

import com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer; //导入依赖的package包/类
@Override
public Date deserialize(final JsonParser parser, final DeserializationContext context) throws IOException, JsonProcessingException {
    final String date = parser.getText();

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");

    try {
        return simpleDateFormat.parse(date);
    }
    catch (final ParseException ex) {
        // Not worked, so let the default date serializer give it a try.
        return DateDeserializer.instance.deserialize(parser, context);
    }
}
 
开发者ID:SevenSpikes,项目名称:nopcommerce-api-java-wrapper,代码行数:15,代码来源:FlexDateDeserializer.java


示例5: completeSetup

import com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer; //导入依赖的package包/类
@Test
public void completeSetup() {
	NopAnnotationIntrospector annotationIntrospector = NopAnnotationIntrospector.instance;
	ObjectMapper objectMapper = new ObjectMapper();

	this.factory.setObjectMapper(objectMapper);
	assertTrue(this.factory.isSingleton());
	assertEquals(ObjectMapper.class, this.factory.getObjectType());

	Map<Class<?>, JsonDeserializer<?>> deserializers = new HashMap<Class<?>, JsonDeserializer<?>>();
	deserializers.put(Date.class, new DateDeserializer());

	JsonSerializer<Class<?>> serializer1 = new ClassSerializer();
	JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class);

	// Disable well-known modules detection
	this.factory.setModules(new ArrayList<>());
	this.factory.setSerializers(serializer1);
	this.factory.setSerializersByType(Collections.singletonMap(Boolean.class, serializer2));
	this.factory.setDeserializersByType(deserializers);
	this.factory.setAnnotationIntrospector(annotationIntrospector);

	this.factory.setFeaturesToEnable(SerializationFeature.FAIL_ON_EMPTY_BEANS,
			DeserializationFeature.UNWRAP_ROOT_VALUE,
			JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,
			JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS);

	this.factory.setFeaturesToDisable(MapperFeature.AUTO_DETECT_GETTERS,
			MapperFeature.AUTO_DETECT_FIELDS,
			JsonParser.Feature.AUTO_CLOSE_SOURCE,
			JsonGenerator.Feature.QUOTE_FIELD_NAMES);

	assertFalse(getSerializerFactoryConfig(objectMapper).hasSerializers());
	assertFalse(getDeserializerFactoryConfig(objectMapper).hasDeserializers());

	this.factory.setSerializationInclusion(Include.NON_NULL);
	this.factory.afterPropertiesSet();

	assertSame(objectMapper, this.factory.getObject());
	assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers());
	assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());

	Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
	assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Class.class), null));
	assertSame(serializer2, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null));
	assertNull(serializers.findSerializer(null, SimpleType.construct(Number.class), null));

	assertSame(annotationIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector());
	assertSame(annotationIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector());

	assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
	assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));
	assertTrue(objectMapper.getFactory().isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
	assertTrue(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS));

	assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
	assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
	assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
	assertSame(Include.NON_NULL, objectMapper.getSerializationConfig().getSerializationInclusion());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:64,代码来源:Jackson2ObjectMapperFactoryBeanTests.java


示例6: withDateFormat

import com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer; //导入依赖的package包/类
@Override
protected DateDeserializer withDateFormat(DateFormat df, String formatString) {
    return new DateDeserializer(this, new CustomDateFormat(formatString), formatString);
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:5,代码来源:CustomJsonDateDeseralizer.java


示例7: testCompleteSetup

import com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer; //导入依赖的package包/类
@Test
public void testCompleteSetup() {
	NopAnnotationIntrospector annotationIntrospector = NopAnnotationIntrospector.instance;
	ObjectMapper objectMapper = new ObjectMapper();

	assertTrue(this.factory.isSingleton());
	assertEquals(ObjectMapper.class, this.factory.getObjectType());

	Map<Class<?>, JsonDeserializer<?>> deserializers = new HashMap<Class<?>, JsonDeserializer<?>>();
	deserializers.put(Date.class, new DateDeserializer());

	this.factory.setObjectMapper(objectMapper);
	this.factory.setSerializers(new ClassSerializer());
	this.factory.setDeserializersByType(deserializers);
	this.factory.setAnnotationIntrospector(annotationIntrospector);

	this.factory.setFeaturesToEnable(
			SerializationFeature.FAIL_ON_EMPTY_BEANS,
			DeserializationFeature.UNWRAP_ROOT_VALUE,
			JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,
			JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS);

	this.factory.setFeaturesToDisable(
			MapperFeature.AUTO_DETECT_GETTERS,
			MapperFeature.AUTO_DETECT_FIELDS,
			JsonParser.Feature.AUTO_CLOSE_SOURCE,
			JsonGenerator.Feature.QUOTE_FIELD_NAMES);

	assertFalse(getSerializerFactoryConfig(objectMapper).hasSerializers());
	assertFalse(getDeserializerFactoryConfig(objectMapper).hasDeserializers());

	this.factory.afterPropertiesSet();

	assertTrue(objectMapper == this.factory.getObject());

	assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers());
	assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());

	assertTrue(annotationIntrospector == objectMapper.getSerializationConfig().getAnnotationIntrospector());
	assertTrue(annotationIntrospector == objectMapper.getDeserializationConfig().getAnnotationIntrospector());

	assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
	assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));
	assertTrue(objectMapper.getJsonFactory().isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
	assertTrue(objectMapper.getJsonFactory().isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS));

	assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
	assertFalse(objectMapper.getJsonFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
	assertFalse(objectMapper.getJsonFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:52,代码来源:Jackson2ObjectMapperFactoryBeanTests.java


示例8: CustomDateDeserializer

import com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer; //导入依赖的package包/类
public CustomDateDeserializer(DateDeserializer base){
 super(base, new SimpleDateFormat(DATE_FORMAT), DATE_FORMAT);
}
 
开发者ID:liosha2007,项目名称:temporary-groupdocs-java-sdk,代码行数:4,代码来源:ApiInvoker.java



注:本文中的com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StreamPlan类代码示例发布时间:2022-05-22
下一篇:
Java Within类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap