final SerializationConfig config = prov.getConfig(); if (type.isContainerType()) { if (!staticTyping) { staticTyping = usesStaticTyping(config, beanDesc, null); ser = buildContainerSerializer(prov, type, beanDesc, staticTyping); if (type.isReferenceType()) { ser = findReferenceSerializer(prov, (ReferenceType) type, beanDesc, staticTyping); } else { for (Serializers serializers : customSerializers()) { ser = serializers.findSerializer(config, type, beanDesc); if (ser != null) { ser = findSerializerByAnnotations(prov, type, beanDesc); ser = findSerializerByLookup(type, config, beanDesc, staticTyping); if (ser == null) { ser = findSerializerByPrimaryType(prov, type, beanDesc, staticTyping); if (ser == null) { ser = findBeanSerializer(prov, type, beanDesc); ser = findSerializerByAddonType(config, type, beanDesc, staticTyping); ser = prov.getUnknownTypeSerializer(beanDesc.getBeanClass());
final SerializationConfig config = prov.getConfig(); BeanSerializerBuilder builder = constructBeanSerializerBuilder(beanDesc); builder.setConfig(config); List<BeanPropertyWriter> props = findBeanProperties(prov, beanDesc, builder); if (props == null) { props = new ArrayList<BeanPropertyWriter>(); } else { props = removeOverlappingTypeIds(prov, beanDesc, builder, props); prov.getAnnotationIntrospector().findAndAddVirtualProperties(config, beanDesc.getClassInfo(), props); props = filterBeanProperties(config, beanDesc, props); builder.setObjectIdWriter(constructObjectIdHandler(prov, beanDesc, props)); builder.setProperties(props); builder.setFilterId(findFilterId(config, beanDesc)); boolean staticTyping = config.isEnabled(MapperFeature.USE_STATIC_TYPING); JavaType valueType = type.getContentType(); TypeSerializer typeSer = createTypeSerializer(config, valueType); JsonSerializer<?> anySer = findSerializerFromAnnotation(prov, anyGetter); if (anySer == null) { processViews(config, builder);
/** * Method used by module registration functionality, to attach additional * serializer providers into this serializer factory. This is typically * handled by constructing a new instance with additional serializers, * to ensure thread-safe access. */ @Override public SerializerFactory withConfig(SerializerFactoryConfig config) { if (_factoryConfig == config) { return this; } /* 22-Nov-2010, tatu: Handling of subtypes is tricky if we do immutable-with-copy-ctor; * and we pretty much have to here either choose between losing subtype instance * when registering additional serializers, or losing serializers. * Instead, let's actually just throw an error if this method is called when subtype * has not properly overridden this method; this to indicate problem as soon as possible. */ if (getClass() != BeanSerializerFactory.class) { throw new IllegalStateException("Subtype of BeanSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': cannot instantiate subtype with " +"additional serializer definitions"); } return new BeanSerializerFactory(config); }
/** * Method that will try to construct a {@link BeanSerializer} for * given class. Returns null if no properties are found. */ public JsonSerializer<Object> findBeanSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc) throws JsonMappingException { // First things first: we know some types are not beans... if (!isPotentialBeanType(type.getRawClass())) { // 03-Aug-2012, tatu: Except we do need to allow serializers for Enums, // as per [databind#24] if (!type.isEnumType()) { return null; } } return constructBeanSerializer(prov, beanDesc); }
throws JsonMappingException List<BeanPropertyDefinition> properties = beanDesc.findProperties(); final SerializationConfig config = prov.getConfig(); removeIgnorableTypes(config, beanDesc, properties); if (config.isEnabled(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS)) { removeSetterlessGetters(config, beanDesc, properties); boolean staticTyping = usesStaticTyping(config, beanDesc, null); PropertyBuilder pb = constructPropertyBuilder(config, beanDesc); builder.setTypeId(accessor); result.add(_constructWriter(prov, property, pb, staticTyping, (AnnotatedMethod) accessor)); } else { result.add(_constructWriter(prov, property, pb, staticTyping, (AnnotatedField) accessor));
final SerializationConfig config = prov.getConfig(); BeanDescription beanDesc = config.introspect(origType); JsonSerializer<?> ser = findSerializerFromAnnotation(prov, beanDesc.getClassInfo()); if (ser != null) { return (JsonSerializer<Object>) ser; JavaType type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), origType); if (type == origType) { // no changes, won't force static typing staticTyping = false; } else { // changes; assume static typing; plus, need to re-introspect if class differs staticTyping = true; if (type.getRawClass() != origType.getRawClass()) { beanDesc = config.introspect(type); ser = findSerializerByAnnotations(prov, type, beanDesc); if (ser != null) { return (JsonSerializer<Object>) ser; if (origType.isContainerType()) { if (!staticTyping) { staticTyping = usesStaticTyping(config, beanDesc, null); ser = buildContainerSerializer(prov, type, beanDesc, staticTyping); if (ser != null) { return (JsonSerializer<Object>) ser; for (Serializers serializers : customSerializers()) { ser = serializers.findSerializer(config, type, beanDesc); if (ser != null) {
@Override public void serialize(CommentOptionsExtension commentOptionsExtension, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { if (!(commentOptionsExtension instanceof CommentPayoutBeneficiaries)) { throw new IllegalArgumentException( "Unknown extension type class '" + commentOptionsExtension.getClass().getSimpleName() + "'."); } jsonGenerator.writeStartArray(); jsonGenerator.writeNumber(CommentOptionsExtensionsType.COMMENT_PAYOUT_BENEFICIARIES.ordinal()); JavaType javaType = serializerProvider.constructType(CommentPayoutBeneficiaries.class); BeanDescription beanDesc = serializerProvider.getConfig().introspect(javaType); JsonSerializer<Object> serializer = BeanSerializerFactory.instance.findBeanSerializer(serializerProvider, javaType, beanDesc); serializer.serialize((CommentPayoutBeneficiaries) commentOptionsExtension, jsonGenerator, serializerProvider); jsonGenerator.writeEndArray(); } }
@Override protected void processViews(SerializationConfig config, BeanSerializerBuilder builder) { super.processViews(config, builder); // ignore fields only for concrete class // note, that you can avoid or change this check Class<?> beanClass = builder.getBeanDescription().getBeanClass(); ClassUtil.ClassInfo classInfo = ClassUtil.getClassInfo(beanClass); // if (builder.getBeanDescription().getBeanClass().equals(Entity.class)) // { // get original writer List<BeanPropertyWriter> originalWriters = builder.getProperties(); // create actual writers List<BeanPropertyWriter> writers = new ArrayList<BeanPropertyWriter>(); String[] fs = this._getFilterFields(classInfo); for (BeanPropertyWriter writer : originalWriters) { final String propName = writer.getName(); // if it isn't ignored field, add to actual writers list boolean find = isFilterField( classInfo, propName, fs); if(!find){ writers.add(writer); } } builder.setProperties(writers); } }
List<BeanPropertyWriter> props = builder.getProperties(); boolean includeByDefault = config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION); final int propCount = props.size(); int viewsFound = 0; filtered[i] = constructFilteredBeanWriter(bpw, views); return; builder.setFilteredProperties(filtered);
@Override protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> props) { List<BeanPropertyWriter> superResult = super.filterBeanProperties(config, beanDesc, props); if (DefaultErrorDTO.class.equals(beanDesc.getBeanClass())) { // Filter out empty metadata if desired if (excludeEmptyMetadataFromJson) { BeanPropertyWriter origMetadataPropWriter = findPropWriter(superResult, METADATA_FIELD_NAME); int indexOfOrig = superResult.indexOf(origMetadataPropWriter); superResult.remove(origMetadataPropWriter); superResult.add(indexOfOrig, new MetadataPropertyWriter(origMetadataPropWriter)); } // Add a smart error code writer if desired if (serializeErrorCodeFieldAsIntegerIfPossible) { BeanPropertyWriter origErrorCodePropWriter = findPropWriter(superResult, ERROR_CODE_FIELD_NAME); int indexOfOrig = superResult.indexOf(origErrorCodePropWriter); superResult.remove(origErrorCodePropWriter); superResult.add(indexOfOrig, new SmartErrorCodePropertyWriter(origErrorCodePropWriter)); } } return superResult; }
/** * Deprecated method; final to help identify problems with sub-classes, * as this method will NOT be called any more in 2.1 * * @deprecated Since 2.1 (use variant without 'property' argument). */ @Deprecated public final JsonSerializer<Object> findBeanSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc, BeanProperty property) throws JsonMappingException { return findBeanSerializer(prov, type, beanDesc); }
@Override public List<BeanPropertyWriter> findBeanProperties(SerializerProvider prov, BeanDescription beanDesc, BeanSerializerBuilder builder) throws JsonMappingException { return super.findBeanProperties(prov, beanDesc, builder); }
/** * Deprecated method; final to help identify problems with sub-classes, * as this method will NOT be called any more in 2.1 * * @deprecated Since 2.1, do not pass 'property' argument */ @Deprecated protected final JsonSerializer<Object> constructBeanSerializer(SerializerProvider prov, BeanDescription beanDesc, BeanProperty property) throws JsonMappingException { return constructBeanSerializer(prov, beanDesc); }
/** * Method that will try to construct a {@link BeanSerializer} for * given class. Returns null if no properties are found. */ public JsonSerializer<Object> findBeanSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc) throws JsonMappingException { // First things first: we know some types are not beans... if (!isPotentialBeanType(type.getRawClass())) { // 03-Aug-2012, tatu: Except we do need to allow serializers for Enums, // as per [Issue#24] if (!type.isEnumType()) { return null; } } return constructBeanSerializer(prov, beanDesc); }
final SerializationConfig config = prov.getConfig(); BeanDescription beanDesc = config.introspect(origType); JsonSerializer<?> ser = findSerializerFromAnnotation(prov, beanDesc.getClassInfo()); if (ser != null) { return (JsonSerializer<Object>) ser; JavaType type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), origType); if (type == origType) { // no changes, won't force static typing staticTyping = false; } else { // changes; assume static typing; plus, need to re-introspect if class differs staticTyping = true; if (type.getRawClass() != origType.getRawClass()) { beanDesc = config.introspect(type); ser = findSerializerByAnnotations(prov, type, beanDesc); if (ser != null) { return (JsonSerializer<Object>) ser; if (origType.isContainerType()) { if (!staticTyping) { staticTyping = usesStaticTyping(config, beanDesc, null, property); return (JsonSerializer<Object>) buildContainerSerializer(prov, type, beanDesc, property, staticTyping); ser = findSerializerByLookup(type, config, beanDesc, staticTyping); if (ser == null) { ser = findSerializerByPrimaryType(prov, type, beanDesc, staticTyping); if (ser == null) {
throws JsonMappingException List<BeanPropertyDefinition> properties = beanDesc.findProperties(); final SerializationConfig config = prov.getConfig(); removeIgnorableTypes(config, beanDesc, properties); if (config.isEnabled(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS)) { removeSetterlessGetters(config, beanDesc, properties); boolean staticTyping = usesStaticTyping(config, beanDesc, null); PropertyBuilder pb = constructPropertyBuilder(config, beanDesc); builder.setTypeId(accessor); result.add(_constructWriter(prov, property, pb, staticTyping, (AnnotatedMethod) accessor)); } else { result.add(_constructWriter(prov, property, pb, staticTyping, (AnnotatedField) accessor));
@Override public void serialize(CommentOptionsExtension commentOptionsExtension, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { if (!(commentOptionsExtension instanceof CommentPayoutBeneficiaries)) { throw new IllegalArgumentException( "Unknown extension type class '" + commentOptionsExtension.getClass().getSimpleName() + "'."); } jsonGenerator.writeStartArray(); jsonGenerator.writeNumber(CommentOptionsExtensionsType.COMMENT_PAYOUT_BENEFICIARIES.ordinal()); JavaType javaType = serializerProvider.constructType(CommentPayoutBeneficiaries.class); BeanDescription beanDesc = serializerProvider.getConfig().introspect(javaType); JsonSerializer<Object> serializer = BeanSerializerFactory.instance.findBeanSerializer(serializerProvider, javaType, beanDesc); serializer.serialize((CommentPayoutBeneficiaries) commentOptionsExtension, jsonGenerator, serializerProvider); jsonGenerator.writeEndArray(); } }
@Override protected void processViews(SerializationConfig config, BeanSerializerBuilder builder) { super.processViews(config, builder); // ignore fields only for concrete class // note, that you can avoid or change this check Class<?> beanClass = builder.getBeanDescription().getBeanClass(); ClassUtil.ClassInfo classInfo = ClassUtil.getClassInfo(beanClass); // if (builder.getBeanDescription().getBeanClass().equals(Entity.class)) // { // get original writer List<BeanPropertyWriter> originalWriters = builder.getProperties(); // create actual writers List<BeanPropertyWriter> writers = new ArrayList<BeanPropertyWriter>(); String[] fs = this._getFilterFields(classInfo); for (BeanPropertyWriter writer : originalWriters) { final String propName = writer.getName(); // if it isn't ignored field, add to actual writers list boolean find = isFilterField( classInfo, propName, fs); if(!find){ writers.add(writer); } } builder.setProperties(writers); } }
List<BeanPropertyWriter> props = builder.getProperties(); boolean includeByDefault = config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION); final int propCount = props.size(); int viewsFound = 0; filtered[i] = constructFilteredBeanWriter(bpw, views); return; builder.setFilteredProperties(filtered);
final SerializationConfig config = prov.getConfig(); BeanSerializerBuilder builder = constructBeanSerializerBuilder(beanDesc); builder.setConfig(config); List<BeanPropertyWriter> props = findBeanProperties(prov, beanDesc, builder); if (props == null) { props = new ArrayList<BeanPropertyWriter>(); } else { props = removeOverlappingTypeIds(prov, beanDesc, builder, props); prov.getAnnotationIntrospector().findAndAddVirtualProperties(config, beanDesc.getClassInfo(), props); props = filterBeanProperties(config, beanDesc, props); builder.setObjectIdWriter(constructObjectIdHandler(prov, beanDesc, props)); builder.setProperties(props); builder.setFilterId(findFilterId(config, beanDesc)); boolean staticTyping = config.isEnabled(MapperFeature.USE_STATIC_TYPING); JavaType valueType = type.getContentType(); TypeSerializer typeSer = createTypeSerializer(config, valueType); JsonSerializer<?> anySer = findSerializerFromAnnotation(prov, anyGetter); if (anySer == null) { processViews(config, builder);