/** * Factory method for constructing an "empty" serializer; one that * outputs no properties (but handles JSON objects properly, including * type information) */ public BeanSerializer createDummy() { return BeanSerializer.createDummy(_beanDesc.getBeanClass()); } }
throws JsonMappingException List<BeanPropertyDefinition> props = beanDesc.findProperties(); Boolean B = intr.findIgnoreUnknownProperties(beanDesc.getClassInfo()); if (B != null) { ignoreAny = B.booleanValue(); Set<String> ignored = ArrayBuilders.arrayToSet(intr.findPropertiesToIgnore(beanDesc.getClassInfo())); for (String propName : ignored) { builder.addIgnorable(propName); AnnotatedMethod anySetter = beanDesc.findAnySetter(); beanDesc.getIgnoredPropertyNames() : beanDesc.getIgnoredPropertyNamesForDeser(); if (ignored2 != null) { for (String propName : ignored2) {
/** * Factory method to use for constructing an instance to use for purposes * other than building serializers or deserializers; will only have information * on class, not on properties. * * @since 1.9 */ public static BasicBeanDescription forOtherUse(MapperConfig<?> config, JavaType type, AnnotatedClass ac) { return new BasicBeanDescription(config, type, ac, Collections.<BeanPropertyDefinition>emptyList()); }
protected Object getDefaultBean() { if (_defaultBean == null) { /* If we can fix access rights, we should; otherwise non-public * classes or default constructor will prevent instantiation */ _defaultBean = _beanDesc.instantiateBean(_config.isEnabled(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)); if (_defaultBean == null) { Class<?> cls = _beanDesc.getClassInfo().getAnnotated(); throw new IllegalArgumentException("Class "+cls.getName()+" has no default constructor; can not instantiate default bean value to support 'properties=JsonSerialize.Inclusion.NON_DEFAULT' annotation"); } } return _defaultBean; }
public static KeyDeserializer findStringBasedKeyDeserializer(DeserializationConfig config, JavaType type) { /* We don't need full deserialization information, just need to * know creators. */ BasicBeanDescription beanDesc = config.introspect(type); // Ok, so: can we find T(String) constructor? Constructor<?> ctor = beanDesc.findSingleArgConstructor(String.class); if (ctor != null) { if (config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { ClassUtil.checkAndFixAccess(ctor); } return new StdKeyDeserializer.StringCtorKeyDeserializer(ctor); } /* or if not, "static T valueOf(String)" (or equivalent marked * with @JsonCreator annotation?) */ Method m = beanDesc.findFactoryMethod(String.class); if (m != null){ if (config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { ClassUtil.checkAndFixAccess(m); } return new StdKeyDeserializer.StringFactoryKeyDeserializer(m); } // nope, no such luck... return null; } }
throws JsonMappingException List<BeanPropertyDefinition> properties = beanDesc.findProperties(); AnnotationIntrospector intr = config.getAnnotationIntrospector(); TypeBindings typeBind = beanDesc.bindingsForBeanType();
if (beanDesc.getType().isConcrete()) { AnnotatedConstructor defaultCtor = beanDesc.findDefaultConstructor(); if (defaultCtor != null) { if (fixAccess) { vchecker = config.getAnnotationIntrospector().findAutoDetectVisibility(beanDesc.getClassInfo(), vchecker);
if (beanDesc.getBeanClass() == Object.class) { throw new IllegalArgumentException("Can not create bean serializer for Object.class"); builder.setFilterId(findFilterId(config, beanDesc)); AnnotatedMethod anyGetter = beanDesc.findAnyGetter(); if (anyGetter != null) { // since 1.6 if (config.isEnabled(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { anyGetter.fixAccess(); JavaType type = anyGetter.getType(beanDesc.bindingsForBeanType()); if (beanDesc.hasKnownClassAnnotations()) { return builder.createDummy();
Map<String,AnnotatedMethod> setters = beanDesc.findSetters(autodetect); AnnotatedMethod anySetter = beanDesc.findAnySetter(); boolean ignoreAny = false; Boolean B = intr.findIgnoreUnknownProperties(beanDesc.getClassInfo()); if (B != null) { ignoreAny = B.booleanValue(); HashSet<String> ignored = ArrayBuilders.arrayToSet(intr.findPropertiesToIgnore(beanDesc.getClassInfo())); AnnotatedClass ac = beanDesc.getClassInfo(); for (AnnotatedMethod am : ac.ignoredMemberMethods()) { String name = beanDesc.okNameForSetter(am); if (name != null) { deser.addIgnorable(name); Map<String,AnnotatedMethod> getters = beanDesc.findGetters(true, false, addedProps); for (Map.Entry<String,AnnotatedMethod> en : getters.entrySet()) { AnnotatedMethod getter = en.getValue(); LinkedHashMap<String,AnnotatedField> fieldsByProp = beanDesc.findDeserializableFields(config.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_FIELDS), addedProps); for (Map.Entry<String,AnnotatedField> en : fieldsByProp.entrySet()) { String name = en.getKey();
/** * Method called to find filter that is configured to be used with bean * serializer being built, if any. * * @since 1.7 */ protected Object findFilterId(SerializationConfig config, BasicBeanDescription beanDesc) { return config.getAnnotationIntrospector().findFilterId(beanDesc.getClassInfo()); }
@SuppressWarnings("deprecation") @Override public LinkedHashMap<String,AnnotatedField> findSerializableFields(VisibilityChecker<?> visibilityChecker, Collection<String> ignoredProperties) { return _findPropertyFields(ignoredProperties, true); }
JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo()); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type); Constructor<Map<Object,Object>> defaultCtor = (Constructor<Map<Object,Object>>) beanDesc.findDefaultConstructor(); if (defaultCtor != null) { if (fixAccess) { md.setIgnorableProperties(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo())); md.setCreators(findMapCreators(config, beanDesc)); md.validateCreators();
JsonDeserializer<?> des = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (des != null) { return des; for (AnnotatedMethod factory : beanDesc.getFactoryMethods()) { if (config.getAnnotationIntrospector().hasCreatorAnnotation(factory)) { int argCount = factory.getParameterCount();
AnnotatedMethod am = beanDesc.findMethod("initCause", INIT_CAUSE_PARAMS); if (am != null) { // should never be null SettableBeanProperty prop = constructSettableProperty(config, beanDesc, "cause", am);
AnnotatedMethod valueMethod = beanDesc.findJsonValueMethod(); if (valueMethod != null) {
for (BeanPropertyDefinition prop : beanDesc.findProperties()) { AnnotatedMethod setter = prop.getSetter(); if (setter != null && setter.getParameterClass(0).isInterface()) { Class<?>[] interfaces = beanDesc.getBeanClass().getInterfaces(); if (interfaces.length == 1) { synchronized (serializerClasses) { return new ClassTypeFieldSerializer(interfaces[0], (BeanSerializerBase) serializer); else return new NoPropertiesSerializer(interfaces[0], beanDesc.getBeanClass());
/** * Method that is to find all creators (constructors, factory methods) * for the bean type to deserialize. */ protected void addDeserializerCreators(DeserializationConfig config, BasicBeanDescription beanDesc, BeanDeserializer deser) throws JsonMappingException { AnnotationIntrospector intr = config.getAnnotationIntrospector(); boolean fixAccess = config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS); // First, let's figure out constructor/factor- based instantation Constructor<?> defaultCtor = beanDesc.findDefaultConstructor(); if (defaultCtor != null) { if (fixAccess) { ClassUtil.checkAndFixAccess(defaultCtor); } deser.setDefaultConstructor(defaultCtor); } CreatorContainer creators = new CreatorContainer(beanDesc.getBeanClass(), fixAccess); _addDeserializerConstructors(config, beanDesc, deser, intr, creators); _addDeserializerFactoryMethods(config, beanDesc, deser, intr, creators); deser.setCreators(creators); }
@Override public JsonSerializer<?> modifySerializer(SerializationConfig config, BasicBeanDescription beanDesc, JsonSerializer<?> serializer) { if(serializer instanceof BeanSerializer) { List<BeanPropertyDefinition> properties = beanDesc.findProperties(); for(BeanPropertyDefinition property : properties) { if(property.getName().equals("value") || property.getName().equals("any")) { String fieldName = property.getField().getName(); if(fieldName != null) return super.modifySerializer(config, beanDesc, new CustomValueObjectSerializer((BeanSerializer)serializer, fieldName)); } } } return super.modifySerializer(config, beanDesc, serializer); } }
if (beanDesc.getType().isConcrete()) { AnnotatedConstructor defaultCtor = beanDesc.findDefaultConstructor(); if (defaultCtor != null) { if (fixAccess) { vchecker = config.getAnnotationIntrospector().findAutoDetectVisibility(beanDesc.getClassInfo(), vchecker);
if (beanDesc.getBeanClass() == Object.class) { throw new IllegalArgumentException("Can not create bean serializer for Object.class"); builder.setFilterId(findFilterId(config, beanDesc)); AnnotatedMethod anyGetter = beanDesc.findAnyGetter(); if (anyGetter != null) { // since 1.6 if (config.isEnabled(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { anyGetter.fixAccess(); JavaType type = anyGetter.getType(beanDesc.bindingsForBeanType()); if (beanDesc.hasKnownClassAnnotations()) { return builder.createDummy();