@Override public BeanPropertyDefinition withSimpleName(String newName) { if (_fullName.hasSimpleName(newName) && !_fullName.hasNamespace()) { return this; } return new SimpleBeanPropertyDefinition(_annotationIntrospector, _member, new PropertyName(newName), _metadata, _inclusion); }
_serializeNull(gen); return; if ((rootType != null) && !rootType.getRawClass().isAssignableFrom(value.getClass())) { _reportIncompatibleRootType(value, rootType); PropertyName rootName = _config.getFullRootName(); if (rootName == null) { wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE); if (wrap) { gen.writeStartObject(); PropertyName pname = _config.findRootName(value.getClass()); gen.writeFieldName(pname.simpleAsEncoded(_config)); } else if (rootName.isEmpty()) { wrap = false; } else { wrap = true; gen.writeStartObject(); gen.writeFieldName(rootName.getSimpleName()); valueSer.serializeWithType(value, gen, this, typeSer); if (wrap) { gen.writeEndObject();
public PropertyName findRootName(Class<?> rootType, MapperConfig<?> config) { ClassKey key = new ClassKey(rootType); PropertyName name = _rootNames.get(key); if (name != null) { return name; } BeanDescription beanDesc = config.introspectClassAnnotations(rootType); AnnotationIntrospector intr = config.getAnnotationIntrospector(); AnnotatedClass ac = beanDesc.getClassInfo(); name = intr.findRootName(ac); // No answer so far? Let's just default to using simple class name if (name == null || !name.hasSimpleName()) { // Should we strip out enclosing class tho? For now, nope: name = PropertyName.construct(rootType.getSimpleName()); } _rootNames.put(key, name); return name; }
/** * Method called to check to see if this property has a name that would * conflict with a given name. * * @since 2.6 */ public boolean wouldConflictWithName(PropertyName name) { if (_wrapperName != null) { return _wrapperName.equals(name); } // Bit convoluted since our support for namespaces is spotty but: return name.hasSimpleName(_name.getValue()) && !name.hasNamespace(); }
/** * @since 2.3 */ public SettableBeanProperty withSimpleName(String simpleName) { PropertyName n = (_propName == null) ? new PropertyName(simpleName) : _propName.withSimpleName(simpleName); return (n == _propName) ? this : withName(n); }
continue; PropertyName wrapperName = _annotationIntrospector.findWrapperName(member); if (wrapperName == null || !wrapperName.hasSimpleName()) { continue; if (!wrapperName.equals(prop.getFullName())) { if (renamed == null) { renamed = new LinkedList<POJOPropertyBuilder>(); renamed.add(prop); it.remove();
if (ai.hasAnyGetterAnnotation(m)) { if (_anyGetters == null) { _anyGetters = new LinkedList<AnnotatedMember>(); _anyGetters.add(m); return; if (ai.hasAsValueAnnotation(m)) { if (_jsonValueGetters == null) { _jsonValueGetters = new LinkedList<AnnotatedMethod>(); _jsonValueGetters.add(m); PropertyName pn = (ai == null) ? null : ai.findNameForSerialization(m); String explName = (pn == null) ? null : pn.getSimpleName(); if (explName == null) { // no explicit name; must follow naming convention implName = BeanUtil.okNameForRegularGetter(m, m.getName()); return; visible = _visibilityChecker.isIsGetterVisible(m); } else { visible = _visibilityChecker.isGetterVisible(m);
continue; PropertyName wrapperName = _annotationIntrospector.findWrapperName(member); if (wrapperName == null || !wrapperName.hasSimpleName()) { continue; String name = wrapperName.getSimpleName(); if (!name.equals(prop.getName())) { if (renamed == null) { renamed = new LinkedList<POJOPropertyBuilder>(); renamed.add(prop); it.remove();
String impl = _annotationIntrospector.findImplicitPropertyName(param); if (impl == null) { impl = ""; PropertyName pn = _annotationIntrospector.findNameForDeserialization(param); boolean expl = (pn != null && !pn.isEmpty()); if (!expl) { if (impl.isEmpty()) { if (!_annotationIntrospector.hasCreatorAnnotation(param.getOwner())) { return; pn = new PropertyName(impl); _creatorProperties.add(prop);
String impl = _annotationIntrospector.findImplicitPropertyName(param); if (impl == null) { impl = ""; PropertyName pn = _annotationIntrospector.findNameForDeserialization(param); boolean expl = (pn != null && !pn.isEmpty()); if (!expl) { if (impl.isEmpty()) { JsonCreator.Mode creatorMode = _annotationIntrospector.findCreatorAnnotation(_config, param.getOwner()); if ((creatorMode == null) || (creatorMode == JsonCreator.Mode.DISABLED)) { return; pn = PropertyName.construct(impl); ? _property(props, pn) : _property(props, impl); prop.addCtor(param, pn, expl, true, false); _creatorProperties.add(prop);
String impl = _annotationIntrospector.findImplicitPropertyName(param); if (impl == null) { impl = ""; PropertyName pn = _annotationIntrospector.findNameForDeserialization(param); boolean expl = (pn != null && !pn.isEmpty()); if (!expl) { if (impl.isEmpty()) { if (!_annotationIntrospector.hasCreatorAnnotation(param.getOwner())) { return; pn = PropertyName.construct(impl); ? _property(props, pn) : _property(props, impl); prop.addCtor(param, pn, expl, true, false); _creatorProperties.add(prop);
_serializeNull(gen); return; if (!rootType.getRawClass().isAssignableFrom(value.getClass())) { _reportIncompatibleRootType(value, rootType); JsonSerializer<Object> ser = findTypedValueSerializer(rootType, true, null); PropertyName rootName = _config.getFullRootName(); if (rootName == null) { // not explicitly specified wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE); if (wrap) { gen.writeStartObject(); PropertyName pname = _config.findRootName(value.getClass()); gen.writeFieldName(pname.simpleAsEncoded(_config)); } else if (rootName.isEmpty()) { wrap = false; } else { gen.writeFieldName(rootName.getSimpleName()); ser.serialize(value, gen, this); if (wrap) { gen.writeEndObject();
protected String _findTypeName(JavaType type, BeanDescription beanDesc) { // First, handle container types; they require recursion if (type.isArrayType()) { return "Array"; } if (type.isMapLikeType() && ReflectionUtils.isSystemType(type)) { return "Map"; } if (type.isContainerType() && ReflectionUtils.isSystemType(type)) { if (Set.class.isAssignableFrom(type.getRawClass())) { return "Set"; } return "List"; } if (beanDesc == null) { beanDesc = _mapper.getSerializationConfig().introspectClassAnnotations(type); } PropertyName rootName = _intr.findRootName(beanDesc.getClassInfo()); if (rootName != null && rootName.hasSimpleName()) { return rootName.getSimpleName(); } return _typeNameResolver.nameForType(type); }
protected BeanPropertyWriter _constructVirtualProperty(JsonAppend.Attr attr, MapperConfig<?> config, AnnotatedClass ac, JavaType type) { PropertyMetadata metadata = attr.required() ? PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL; // could add Index, Description in future, if those matter String attrName = attr.value(); // allow explicit renaming; if none, default to attribute name PropertyName propName = _propertyName(attr.propName(), attr.propNamespace()); if (!propName.hasSimpleName()) { propName = new PropertyName(attrName); } // now, then, we need a placeholder for member (no real Field/Method): AnnotatedMember member = new VirtualAnnotatedMember(ac, ac.getRawType(), attrName, type.getRawClass()); // and with that and property definition SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(config, member, propName, metadata, attr.include()); // can construct the property writer return AttributePropertyWriter.construct(attrName, propDef, ac.getAnnotations(), type); }
BeanDescription desc = config.introspectClassAnnotations(_beanType); 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()); String propName = objectIdInfo.getPropertyName().getSimpleName(); BeanPropertyWriter idProp = null;
@Override public ObjectIdInfo findObjectIdInfo(Annotated annotated) { Class<?> rawClass = annotated.getType().getRawClass(); for (Type<?> type : model.getTypes()) { if (type.getClassType() == rawClass && type.getSingleKeyAttribute() != null) { return new ObjectIdInfo(new PropertyName(name), rawClass, ObjectIdGenerators.PropertyGenerator.class, EntityStoreResolver.class); return super.findObjectIdInfo(annotated);
if (beanDesc.getBeanClass() == Object.class) { return prov.getUnknownTypeSerializer(Object.class); prov.getAnnotationIntrospector().findAndAddVirtualProperties(config, beanDesc.getClassInfo(), props); builder.setFilterId(findFilterId(config, beanDesc)); AnnotatedMember anyGetter = beanDesc.findAnyGetter(); if (anyGetter != null) { JavaType type = anyGetter.getType(); boolean staticTyping = config.isEnabled(MapperFeature.USE_STATIC_TYPING); JavaType valueType = type.getContentType(); TypeSerializer typeSer = createTypeSerializer(config, valueType); PropertyName name = PropertyName.construct(anyGetter.getName()); BeanProperty.Std anyProp = new BeanProperty.Std(name, valueType, null, anyGetter, PropertyMetadata.STD_OPTIONAL);
valueType = am.getParameterType(1); valueType = resolveMemberAndTypeAnnotations(ctxt, mutator, valueType); prop = new BeanProperty.Std(PropertyName.construct(mutator.getName()), valueType, null, mutator, PropertyMetadata.STD_OPTIONAL); keyType = mapType.getKeyType(); valueType = mapType.getContentType(); prop = new BeanProperty.Std(PropertyName.construct(mutator.getName()), mapType, null, mutator, PropertyMetadata.STD_OPTIONAL); } else { return ctxt.reportBadDefinition(beanDesc.getType(), String.format( "Unrecognized mutator type for any setter: %s", mutator.getClass())); keyDeser = keyType.getValueHandler(); keyDeser = ctxt.findKeyDeserializer(keyType, prop); } else { if (keyDeser instanceof ContextualKeyDeserializer) { deser = (JsonDeserializer<Object>) ctxt.handlePrimaryContextualization(deser, prop, valueType); TypeDeserializer typeDeser = valueType.getTypeHandler();
_serializeNull(gen); return; final JsonSerializer<Object> ser = findTypedValueSerializer(cls, true, null); PropertyName rootName = _config.getFullRootName(); wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE); if (wrap) { gen.writeStartObject(); PropertyName pname = _config.findRootName(value.getClass()); gen.writeFieldName(pname.simpleAsEncoded(_config)); } else if (rootName.isEmpty()) { wrap = false; } else { // [JACKSON-764] gen.writeFieldName(rootName.getSimpleName()); ser.serialize(value, gen, this); if (wrap) { gen.writeEndObject();
BeanProperty property) throws JsonMappingException final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector(); if (property != null && intr != null) { final AnnotatedMember accessor = property.getMember(); if (accessor != null) { ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor); if (objectIdInfo != null) { // some code duplication here as well (from BeanDeserializerFactory) JavaType idType; ObjectIdGenerator<?> idGen; SettableBeanProperty idProp = null; ObjectIdResolver resolver = ctxt.objectIdResolverInstance(accessor, objectIdInfo); objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo); Class<?> implClass = objectIdInfo.getGeneratorType(); idProp = (_properties == null) ? null : _properties.get(propName.getSimpleName()); if (idProp == null) { ctxt.reportBadDefinition(_baseType, String.format( "Invalid Object Id definition for %s: cannot find property with name '%s'", handledType().getName(), propName));