protected JsonSerializer<?> buildEnumSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) throws JsonMappingException { /* As per [databind#24], may want to use alternate shape, serialize as JSON Object. * Challenge here is that EnumSerializer does not know how to produce * POJO style serialization, so we must handle that special case separately; * otherwise pass it to EnumSerializer. */ JsonFormat.Value format = beanDesc.findExpectedFormat(null); if (format != null && format.getShape() == JsonFormat.Shape.OBJECT) { // one special case: suppress serialization of "getDeclaringClass()"... ((BasicBeanDescription) beanDesc).removeProperty("declaringClass"); // returning null will mean that eventually BeanSerializer gets constructed return null; } @SuppressWarnings("unchecked") Class<Enum<?>> enumClass = (Class<Enum<?>>) type.getRawClass(); JsonSerializer<?> ser = EnumSerializer.construct(enumClass, config, beanDesc, format); // [databind#120]: Allow post-processing if (_factoryConfig.hasSerializerModifiers()) { for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) { ser = mod.modifyEnumSerializer(config, type, beanDesc, ser); } } return ser; }
JsonFormat.Shape shape = format.getShape(); if (shape.isNumeric()) { return withFormat(Boolean.TRUE, null); if (format.hasPattern()) { final Locale loc = format.hasLocale() ? format.getLocale() : serializers.getLocale(); SimpleDateFormat df = new SimpleDateFormat(format.getPattern(), loc); TimeZone tz = format.hasTimeZone() ? format.getTimeZone() : serializers.getTimeZone(); df.setTimeZone(tz); return withFormat(Boolean.FALSE, df); final boolean hasLocale = format.hasLocale(); final boolean hasTZ = format.hasTimeZone(); final boolean asString = (shape == JsonFormat.Shape.STRING); if (format.hasLocale()) { std = std.withLocale(format.getLocale()); if (format.hasTimeZone()) { std = std.withTimeZone(format.getTimeZone()); df = new SimpleDateFormat(df.toPattern(), format.getLocale()); } else { df = (SimpleDateFormat) df.clone(); TimeZone newTz = format.getTimeZone();
/** * @since 2.9 */ public static Value forLeniency(boolean lenient) { return new Value(null, null, null, null, null, Features.empty(), Boolean.valueOf(lenient)); }
if (type.isEnumType()) { return factory.createEnumDeserializer(ctxt, type, beanDesc); if (type.isContainerType()) { if (type.isArrayType()) { return factory.createArrayDeserializer(ctxt, (ArrayType) type, beanDesc); JsonFormat.Value format = beanDesc.findExpectedFormat(null); if ((format == null) || format.getShape() != JsonFormat.Shape.OBJECT) { MapLikeType mlt = (MapLikeType) type; if (mlt.isTrueMapType()) { JsonFormat.Value format = beanDesc.findExpectedFormat(null); if ((format == null) || format.getShape() != JsonFormat.Shape.OBJECT) { CollectionLikeType clt = (CollectionLikeType) type; if (clt.isTrueCollectionType()) {
throws JsonMappingException if ((format != null) && format.hasShape()) { shape = format.getShape(); JsonSerializer<?> ser = EnumSerializer.construct(_beanType.getRawClass(), provider.getConfig(), desc, format); return provider.handlePrimaryContextualization(ser, property); if (_beanType.isMapLikeType() && Map.class.isAssignableFrom(_handledType)) { JavaType mapEntryType = _beanType.findSuperType(Map.Entry.class); JavaType kt = mapEntryType.containedTypeOrUnknown(0); JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(accessor); if (ignorals != null) { ignoredProps = ignorals.findIgnoredForSerialization(); ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor); if (objectIdInfo == null) { objectIdInfo = intr.findObjectReferenceInfo(accessor, null); if (objectIdInfo != null) { oiw = _objectIdWriter.withAlwaysAsId(objectIdInfo.getAlwaysAsId());
throws JsonMappingException Class<?> raw = type.getRawClass(); JavaType mapEntryType = type.findSuperType(Map.Entry.class); JavaType kt = mapEntryType.containedTypeOrUnknown(0); JavaType vt = mapEntryType.containedTypeOrUnknown(1); return buildMapEntrySerializer(prov, type, beanDesc, staticTyping, kt, vt); JsonFormat.Value format = beanDesc.findExpectedFormat(null); if (format != null) { switch (format.getShape()) { case STRING: return ToStringSerializer.instance; return buildEnumSerializer(prov.getConfig(), type, beanDesc);
throws JsonMappingException Class<?> raw = type.getRawClass(); JavaType[] params = prov.getTypeFactory().findTypeParameters(type, Map.Entry.class); if (params == null || params.length != 2) { // assume that if we don't get 2, they are wrong... kt = vt = TypeFactory.unknownType(); vt = params[1]; return buildMapEntrySerializer(prov.getConfig(), type, beanDesc, staticTyping, kt, vt); JsonFormat.Value format = beanDesc.findExpectedFormat(null); if (format != null) { switch (format.getShape()) { case STRING: return ToStringSerializer.instance; return buildEnumSerializer(prov.getConfig(), type, beanDesc);
final AnnotationIntrospector intr = provider.getAnnotationIntrospector(); final AnnotatedMember propertyAcc = (property == null) ? null : property.getMember(); Object serDef = intr.findKeySerializer(propertyAcc); if (serDef != null) { keySer = provider.serializerInstance(propertyAcc, serDef); serDef = intr.findContentSerializer(propertyAcc); if (serDef != null) { ser = provider.serializerInstance(propertyAcc, serDef); if (_valueTypeIsStatic && !_valueType.isJavaLangObject()) { ser = provider.findValueSerializer(_valueType, property); Boolean B = format.getFeature(JsonFormat.Feature.WRITE_SORTED_MAP_ENTRIES); if (B != null) { sortKeys = B.booleanValue(); AnnotatedMember m = property.getMember(); if (m != null) { Object filterId = intr.findFilterId(m); JsonInclude.Value inclV = property.findPropertyInclusion(provider.getConfig(), null); if (inclV != null) { JsonInclude.Include incl = inclV.getContentInclusion();
AnnotatedMember m = property.getMember(); final AnnotationIntrospector intr = serializers.getAnnotationIntrospector(); if (m != null) { Object serDef = intr.findContentSerializer(m); if (serDef != null) { ser = serializers.serializerInstance(m, serDef); unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED); if (_staticTyping && !_elementType.isJavaLangObject()) { ser = serializers.findValueSerializer(_elementType, property);
throws JsonMappingException Class<?> raw = type.getRawClass(); JsonSerializer<?> ser = optionalHandlers.findSerializer(prov.getConfig(), type); if (ser != null) { return ser; JsonFormat.Value format = beanDesc.findExpectedFormat(null); if (format != null && format.getShape() == JsonFormat.Shape.OBJECT) { @SuppressWarnings("unchecked") Class<Enum<?>> enumClass = (Class<Enum<?>>) raw; return EnumSerializer.construct(enumClass, prov.getConfig(), beanDesc, format);
throws JsonMappingException final SerializationConfig config = prov.getConfig(); JavaType elementType = type.getContentType(); TypeSerializer elementTypeSerializer = createTypeSerializer(config, elementType); beanDesc.getClassInfo()); if (type.isMapLikeType()) { // implements java.util.Map MapLikeType mlt = (MapLikeType) type; JsonSerializer<Object> keySerializer = _findKeySerializer(prov, beanDesc.getClassInfo()); if (mlt.isTrueMapType()) { return buildMapSerializer(config, (MapType) mlt, beanDesc, staticTyping, if (type.isCollectionLikeType()) { CollectionLikeType clt = (CollectionLikeType) type; if (clt.isTrueCollectionType()) { // only have custom ones, if any: JsonFormat.Value format = beanDesc.findExpectedFormat(null); if (format == null || format.getShape() != JsonFormat.Shape.OBJECT) { return buildCollectionSerializer(config, trueCT, beanDesc, staticTyping, elementTypeSerializer, elementValueSerializer);
if (valueSer == null) { // if type is final, can actually resolve: JavaType valueType = _type.getContentType(); if (valueType.isFinal()) { valueSer = provider.findValueSerializer(valueType, property); final AnnotationIntrospector intr = provider.getAnnotationIntrospector(); final AnnotatedMember propertyAcc = (property == null) ? null : property.getMember(); JsonSerializer<?> keySer = null; Object filterId = _filterId; Object serDef = intr.findKeySerializer(propertyAcc); if (serDef != null) { keySer = provider.serializerInstance(propertyAcc, serDef); serDef = intr.findContentSerializer(propertyAcc); if (serDef != null) { valueSer = provider.serializerInstance(propertyAcc, serDef); filterId = intr.findFilterId(propertyAcc); if (valueType.useStaticType()) { valueSer = provider.findValueSerializer(valueType, property); Boolean B = format.getFeature(JsonFormat.Feature.WRITE_SORTED_MAP_ENTRIES); if (B != null) { sortKeys = B.booleanValue();
JsonFormat.Value format = prov.getAnnotationIntrospector().findFormat(property.getMember()); if (format != null) { if (format.getShape().isNumeric()) { return withFormat(true, null); TimeZone tz = format.getTimeZone(); String pattern = format.getPattern(); if (pattern.length() > 0){ Locale loc = format.getLocale(); if (loc == null) { loc = prov.getLocale(); tz = prov.getTimeZone();
final AnnotationIntrospector intr = serializers.getAnnotationIntrospector(); AnnotatedMember m = property.getMember(); if (m != null) { Object serDef = intr.findContentSerializer(m); if (serDef != null) { ser = serializers.serializerInstance(m, serDef); unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED); ser = serializers.findValueSerializer(String.class, property);
JsonFormat.Value format = beanDesc.findExpectedFormat(null); if ((format != null) && format.getShape() == JsonFormat.Shape.OBJECT) { return null; final SerializationConfig config = prov.getConfig(); for (Serializers serializers : customSerializers()) { // (1) Custom ser = serializers.findMapSerializer(config, type, beanDesc, beanDesc.getClassInfo()); Set<String> ignored = (ignorals == null) ? null : ignorals.findIgnoredForSerialization(); if (_factoryConfig.hasSerializerModifiers()) { for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) { ser = mod.modifyMapSerializer(config, type, beanDesc, ser);
JsonFormat.Value formatOverride = prov.getDefaultPropertyFormat(Map.Entry.class); JsonFormat.Value formatFromAnnotation = beanDesc.findExpectedFormat(null); JsonFormat.Value format = JsonFormat.Value.merge(formatFromAnnotation, formatOverride); if (format.getShape() == JsonFormat.Shape.OBJECT) { return null; staticTyping, createTypeSerializer(prov.getConfig(), valueType), null); valueToSuppress = contentType.isReferenceType() ? MapSerializer.MARKER_FOR_EMPTY : null; break; break; case CUSTOM: valueToSuppress = prov.includeFilterInstance(null, inclV.getContentFilter()); if (valueToSuppress == null) { // is this legal? suppressNulls = true;
boolean hasViews) super(beanDesc.getType()); _beanType = beanDesc.getType(); _valueInstantiator = builder.getValueInstantiator(); JsonFormat.Value format = beanDesc.findExpectedFormat(null); _serializationShape = (format == null) ? null : format.getShape();
@Override public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException { if (property != null) { AnnotatedMember m = property.getMember(); if (m != null) { JsonFormat.Value format = prov.getAnnotationIntrospector().findFormat(m); if (format != null) { switch (format.getShape()) { case STRING: return ToStringSerializer.instance; default: } } } } return this; } }
final AnnotatedMember accessor = _neitherNull(property, intr) ? property.getMember() : null; if (accessor != null) { ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor); if (objectIdInfo != null) { // some code duplication here as well (from BeanDeserializerFactory) objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo); JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(accessor); if (ignorals != null) { Set<String> ignored = ignorals.findIgnoredForDeserialization(); JsonFormat.Shape shape = null; if (format != null) { if (format.hasShape()) { shape = format.getShape(); Boolean B = format.getFeature(JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); if (B != null) { BeanPropertyMap propsOrig = _beanProperties;
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { if (property != null) { JsonFormat.Value format = ctxt.getAnnotationIntrospector().findFormat((Annotated) property.getMember()); 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); } return withDateFormat(df); } // any use for TimeZone? } } return this; } }