@Override @SuppressWarnings("unchecked") public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException { JsonSerializer<?> ser = findCustomSerializer(type.getRawClass(), config); if (ser != null) { return (JsonSerializer<Object>) ser; } return super.createSerializer(config, type, property); }
BeanSerializerBuilder builder = constructBeanSerializerBuilder(beanDesc); List<BeanPropertyWriter> props = findBeanProperties(config, beanDesc); props = filterBeanProperties(config, beanDesc, props); props = sortBeanProperties(config, beanDesc, props); builder.setFilterId(findFilterId(config, beanDesc)); TypeSerializer typeSer = createTypeSerializer(config, valueType, property); processViews(config, builder);
JsonSerializer<?> ser = findSerializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (ser != null) { return (JsonSerializer<Object>) ser; JavaType type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), origType); return (JsonSerializer<Object>) buildContainerSerializer(config, type, beanDesc, property, staticTyping); ser = findSerializerByLookup(type, config, beanDesc, property, staticTyping); if (ser == null) { ser = findSerializerByPrimaryType(type, config, beanDesc, property, staticTyping); if (ser == null) { ser = findBeanSerializer(config, type, beanDesc, property); ser = findSerializerByAddonType(config, type, beanDesc, property, staticTyping);
removeIgnorableTypes(config, beanDesc, properties); removeSetterlessGetters(config, beanDesc, properties); boolean staticTyping = usesStaticTyping(config, beanDesc, null, null); PropertyBuilder pb = constructPropertyBuilder(config, beanDesc); result.add(_constructWriter(config, typeBind, pb, staticTyping, name, (AnnotatedMethod) accessor)); } else { result.add(_constructWriter(config, typeBind, pb, staticTyping, name, (AnnotatedField) accessor));
/** * Method that will try to construct a {@link BeanSerializer} for * given class. Returns null if no properties are found. */ @SuppressWarnings("unchecked") public JsonSerializer<Object> findBeanSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property) throws JsonMappingException { // First things first: we know some types are not beans... if (!isPotentialBeanType(type.getRawClass())) { return null; } JsonSerializer<Object> serializer = constructBeanSerializer(config, beanDesc, property); // [JACKSON-440] Need to allow overriding actual serializer, as well... if (_factoryConfig.hasSerializerModifiers()) { for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) { serializer = (JsonSerializer<Object>)mod.modifySerializer(config, beanDesc, serializer); } } return serializer; }
/** * Main serializer constructor method. We will have to be careful * with respect to ordering of various method calls: essentially * we want to reliably figure out which classes are standard types, * and which are beans. The problem is that some bean Classes may * implement standard interfaces (say, {@link java.lang.Iterable}. */ @Override @SuppressWarnings("unchecked") public <T> JsonSerializer<T> createSerializer(Class<T> type) { // First, fast lookup for exact type: JsonSerializer<?> ser = findSerializerByLookup(type); if (ser == null) { // and then introspect for some safe (?) JDK types ser = findSerializerByPrimaryType(type); if (ser == null) { // But if no match, let's see if it might be a bean ser = findBeanSerializer(type); // if not, then fall back to other JDK types if (ser == null) { ser = findSerializerByAddonType(type); } } } return (JsonSerializer<T>) ser; }
protected JsonSerializer<Object> constructBeanSerializer(SerializationConfig config, BasicBeanDescription beanDesc) { // First: any detectable (auto-detect, annotations) properties to serialize? List<BeanPropertyWriter> props = findBeanProperties(config, beanDesc); if (props == null || props.size() == 0) { // No properties, no serializer /* 27-Nov-2009, tatu: Except that as per [JACKSON-201], we are * ok with that as long as it has a recognized class annotation * (which may come from a mix-in too) */ if (beanDesc.hasKnownClassAnnotations()) { return BeanSerializer.createDummy(beanDesc.classDescribed()); } return null; } // Any properties to suppress? props = filterBeanProperties(config, beanDesc, props); // Do they need to be sorted in some special way? props = sortBeanProperties(config, beanDesc, props); BeanSerializer ser = new BeanSerializer(beanDesc.classDescribed(), props); // One more thing: need to gather view information, if any: ser = processViews(config, beanDesc, ser, props); return ser; }
/** * Method that will try to construct a {@link BeanSerializer} for * given class. Returns null if no properties are found. */ public JsonSerializer<Object> findBeanSerializer(Class<?> type, SerializationConfig config, BasicBeanDescription beanDesc) { // First things first: we know some types are not beans... if (!isPotentialBeanType(type)) { return null; } /* [JACKSON-80]: Should support @JsonValue, which is alternative to * actual bean method introspection. */ AnnotatedMethod valueMethod = beanDesc.findJsonValueMethod(); if (valueMethod != null) { /* Further, method itself may also be annotated to indicate * exact JsonSerializer to use for whatever value is returned... */ JsonSerializer<Object> ser = findSerializerFromAnnotation(config, valueMethod); return new JsonValueSerializer(valueMethod.getAnnotated(), ser); } return constructBeanSerializer(config, beanDesc); }
boolean staticTyping = usesStaticTyping(config, beanDesc); PropertyBuilder pb = constructPropertyBuilder(config, beanDesc); JsonSerializer<Object> annotatedSerializer = findSerializerFromAnnotation(config, af); BeanPropertyWriter pbw = pb.buildProperty(en.getKey(), annotatedSerializer, af, staticTyping); JsonSerializer<Object> annotatedSerializer = findSerializerFromAnnotation(config, am); BeanPropertyWriter pbw = pb.buildProperty(en.getKey(), annotatedSerializer, am, staticTyping); pbw.setViews(intr.findSerializationViews(am));
filtered[i] = constructFilteredBeanWriter(bpw, views);
JsonSerializer<?> ser = findSerializerFromAnnotation(config, beanDesc.getClassInfo()); if (ser == null) { ser = this.findBeanSerializer(type, config, beanDesc);
/** * Method that will try to construct a {@link BeanSerializer} for * given class. Returns null if no properties are found. */ protected JsonSerializer<?> findBeanSerializer(Class<?> type) { // First things first: we know some types are not beans... if (!canBeABeanType(type)) { return null; } // First: what properties are to be serializable? Collection<WritableBeanProperty> props = findBeanProperties(type); if (props == null || props.size() == 0) { // No properties, no serializer return null; } return new BeanSerializer(type, props); }
@Override public JsonSerializer<?> findSerializer(final SerializationConfig config, final JavaType type, final BeanDescription beanDesc, final BeanProperty property) { final Class<?> raw = type.getRawClass(); if (fluentIterableClass.isAssignableFrom(raw)) { BasicBeanDescription basicBeanDescription = config.introspect(type); try { return BeanSerializerFactory.instance.findSerializerByAddonType(config, type, basicBeanDescription, property, false); } catch (JsonMappingException e) { // Had no luck - continue with super method } } return super.findSerializer(config, type, beanDesc, property); } };
removeIgnorableTypes(config, beanDesc, properties); removeSetterlessGetters(config, beanDesc, properties); boolean staticTyping = usesStaticTyping(config, beanDesc, null, null); PropertyBuilder pb = constructPropertyBuilder(config, beanDesc); result.add(_constructWriter(config, typeBind, pb, staticTyping, name, (AnnotatedMethod) accessor)); } else { result.add(_constructWriter(config, typeBind, pb, staticTyping, name, (AnnotatedField) accessor));
/** * Method that will try to construct a {@link BeanSerializer} for * given class. Returns null if no properties are found. */ @SuppressWarnings("unchecked") public JsonSerializer<Object> findBeanSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property) throws JsonMappingException { // First things first: we know some types are not beans... if (!isPotentialBeanType(type.getRawClass())) { return null; } JsonSerializer<Object> serializer = constructBeanSerializer(config, beanDesc, property); // [JACKSON-440] Need to allow overriding actual serializer, as well... if (_factoryConfig.hasSerializerModifiers()) { for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) { serializer = (JsonSerializer<Object>)mod.modifySerializer(config, beanDesc, serializer); } } return serializer; }
filtered[i] = constructFilteredBeanWriter(bpw, views);
JsonSerializer<?> ser = findSerializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (ser != null) { return (JsonSerializer<Object>) ser; JavaType type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), origType); return (JsonSerializer<Object>) buildContainerSerializer(config, type, beanDesc, property, staticTyping); ser = findSerializerByLookup(type, config, beanDesc, property, staticTyping); if (ser == null) { ser = findSerializerByPrimaryType(type, config, beanDesc, property, staticTyping); if (ser == null) { ser = findBeanSerializer(config, type, beanDesc, property); ser = findSerializerByAddonType(config, type, beanDesc, property, staticTyping);
BeanSerializerBuilder builder = constructBeanSerializerBuilder(beanDesc); List<BeanPropertyWriter> props = findBeanProperties(config, beanDesc); props = filterBeanProperties(config, beanDesc, props); props = sortBeanProperties(config, beanDesc, props); builder.setFilterId(findFilterId(config, beanDesc)); TypeSerializer typeSer = createTypeSerializer(config, valueType, property); processViews(config, builder);
removeIgnorableTypes(config, beanDesc, properties); removeSetterlessGetters(config, beanDesc, properties); boolean staticTyping = usesStaticTyping(config, beanDesc, null, null); PropertyBuilder pb = constructPropertyBuilder(config, beanDesc); result.add(_constructWriter(config, typeBind, pb, staticTyping, name, (AnnotatedMethod) accessor)); } else { result.add(_constructWriter(config, typeBind, pb, staticTyping, name, (AnnotatedField) accessor));
/** * Method that will try to construct a {@link BeanSerializer} for * given class. Returns null if no properties are found. */ @SuppressWarnings("unchecked") public JsonSerializer<Object> findBeanSerializer(SerializationConfig config, JavaType type, BasicBeanDescription beanDesc, BeanProperty property) throws JsonMappingException { // First things first: we know some types are not beans... if (!isPotentialBeanType(type.getRawClass())) { return null; } JsonSerializer<Object> serializer = constructBeanSerializer(config, beanDesc, property); // [JACKSON-440] Need to allow overriding actual serializer, as well... if (_factoryConfig.hasSerializerModifiers()) { for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) { serializer = (JsonSerializer<Object>)mod.modifySerializer(config, beanDesc, serializer); } } return serializer; }