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


Java JsonFormat.Value方法代码示例

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


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

示例1: createContextual

import com.fasterxml.jackson.annotation.JsonFormat; //导入方法依赖的package包/类
@Override
 public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
         BeanProperty property) throws JsonMappingException
 {
     JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType());
     if (format != null) {
         if (format.hasPattern()) {
             final String pattern = format.getPattern();
             final Locale locale = format.hasLocale() ? format.getLocale() : ctxt.getLocale();
             DateTimeFormatter df;
             if (locale == null) {
                 df = DateTimeFormatter.ofPattern(pattern);
             } else {
                 df = DateTimeFormatter.ofPattern(pattern, locale);
             }
             //Issue #69: For instant serializers/deserializers we need to configure the formatter with
             //a time zone picked up from JsonFormat annotation, otherwise serialization might not work
             if (format.hasTimeZone()) {
                 df = df.withZone(format.getTimeZone().toZoneId());
             }
             return withDateFormat(df);
         }
         // any use for TimeZone?
     }
     return this;
}
 
开发者ID:FasterXML,项目名称:jackson-modules-java8,代码行数:27,代码来源:JSR310DateTimeDeserializerBase.java

示例2: createContextual

import com.fasterxml.jackson.annotation.JsonFormat; //导入方法依赖的package包/类
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    if (property != null) {
        JsonFormat.Value format = ctxt.getAnnotationIntrospector().findFormat(property.getMember());
        if (format != null && Objects.equals(TransactionSerializer.BASE64_FORMAT, format.getPattern())) {
            return new Base64TransactionDeserializer(formatter);
        }
    }

    return new HexTransactionDeserializer(formatter);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:12,代码来源:TransactionDeserializer.java

示例3: createContextual

import com.fasterxml.jackson.annotation.JsonFormat; //导入方法依赖的package包/类
@Override
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
    if (property != null) {
        JsonFormat.Value format = prov.getAnnotationIntrospector().findFormat(property.getMember());
        if (format != null && Objects.equals(BASE64_FORMAT, format.getPattern())) {
            return new Base64TransactionSerializer();
        }
    }

    return new HexTransactionSerializer();
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:12,代码来源:TransactionSerializer.java

示例4: createContextual

import com.fasterxml.jackson.annotation.JsonFormat; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public JsonDeserializer<T> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    InstantDeserializer<T> deserializer =
            (InstantDeserializer<T>)super.createContextual(ctxt, property);
    if (deserializer != this) {
        JsonFormat.Value val = findFormatOverrides(ctxt, property, handledType());
        if (val != null) {
            return  new InstantDeserializer<>(deserializer, val.getFeature(JsonFormat.Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE));
        }
    }
    return this;
}
 
开发者ID:FasterXML,项目名称:jackson-modules-java8,代码行数:16,代码来源:InstantDeserializer.java

示例5: createContextual

import com.fasterxml.jackson.annotation.JsonFormat; //导入方法依赖的package包/类
@Override
public JsonSerializer<?> createContextual(SerializerProvider prov,
        BeanProperty property) throws JsonMappingException
{
    JsonFormat.Value format = findFormatOverrides(prov, property, handledType());
    if (format != null) {
        Boolean useTimestamp = null;

       // Simple case first: serialize as numeric timestamp?
        JsonFormat.Shape shape = format.getShape();
        if (shape == JsonFormat.Shape.ARRAY || shape.isNumeric() ) {
            useTimestamp = Boolean.TRUE;
        } else {
            useTimestamp = (shape == JsonFormat.Shape.STRING) ? Boolean.FALSE : null;
        }
        DateTimeFormatter dtf = _formatter;

        // If not, do we have a pattern?
        if (format.hasPattern()) {
            final String pattern = format.getPattern();
            final Locale locale = format.hasLocale() ? format.getLocale() : prov.getLocale();
            if (locale == null) {
                dtf = DateTimeFormatter.ofPattern(pattern);
            } else {
                dtf = DateTimeFormatter.ofPattern(pattern, locale);
            }
            //Issue #69: For instant serializers/deserializers we need to configure the formatter with
            //a time zone picked up from JsonFormat annotation, otherwise serialization might not work
            if (format.hasTimeZone()) {
                dtf = dtf.withZone(format.getTimeZone().toZoneId());
            }
        }
        JSR310FormattedSerializerBase<?> ser = this;
        if ((shape != _shape) || (useTimestamp != _useTimestamp) || (dtf != _formatter)) {
            ser = ser.withFormat(useTimestamp, dtf, shape);
        }
        Boolean writeZoneId = format.getFeature(JsonFormat.Feature.WRITE_DATES_WITH_ZONE_ID);
        if (writeZoneId != null) {
            ser = ser.withFeatures(writeZoneId);
        }
        return ser;
    }
    return this;
}
 
开发者ID:FasterXML,项目名称:jackson-modules-java8,代码行数:45,代码来源:JSR310FormattedSerializerBase.java


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