本文整理匯總了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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}