protected BeanPropertyWriter _constructVirtualProperty( JsonAppend.Prop prop, MapperConfig<?> config, AnnotatedClass ac) { PropertyMetadata metadata = prop.required() ? PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL; PropertyName propName = _propertyName(prop.name(), prop.namespace()); JavaType type = config.constructType(prop.type()); // now, then, we need a placeholder for member (no real Field/Method): AnnotatedMember member = new VirtualAnnotatedMember( ac, ac.getRawType(), propName.getSimpleName(), type.getRawClass()); // and with that and property definition SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(config, member, propName, metadata, prop.include()); Class<?> implClass = prop.value(); HandlerInstantiator hi = config.getHandlerInstantiator(); VirtualBeanPropertyWriter bpw = (hi == null) ? null : hi.virtualPropertyWriterInstance(config, implClass); if (bpw == null) { bpw = (VirtualBeanPropertyWriter) ClassUtil.createInstance(implClass, config.canOverrideAccessModifiers()); } // one more thing: give it necessary contextual information return bpw.withConfig(config, ac, propDef, type); }
public void testRootNameAccess() throws Exception { AnnotationIntrospector ai = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); // If no @XmlRootElement, should get null (unless pkg has etc) assertNull(ai.findRootName(AnnotatedClass.construct(SimpleBean.class, ai, null))); // With @XmlRootElement, but no name, empty String PropertyName rootName = ai.findRootName(AnnotatedClass.construct(NamespaceBean.class, ai, null)); assertNotNull(rootName); assertEquals("", rootName.getSimpleName()); assertEquals("urn:class", rootName.getNamespace()); // and otherwise explicit name rootName = ai.findRootName(AnnotatedClass.construct(RootNameBean.class, ai, null)); assertNotNull(rootName); assertEquals("test", rootName.getSimpleName()); assertNull(rootName.getNamespace()); }
/** * Additional simple tests to ensure we will retain basic namespace information now that it can be * included * * @since 2.1 */ public void testNamespaces() throws Exception { JaxbAnnotationIntrospector ai = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); AnnotatedClass ac = AnnotatedClass.construct(NamespaceBean.class, ai, null); AnnotatedField af = _findField(ac, "string"); assertNotNull(af); PropertyName pn = ai.findNameForDeserialization(af); assertNotNull(pn); // JAXB seems to assert field name instead of giving "use default"... assertEquals("", pn.getSimpleName()); assertEquals("urn:method", pn.getNamespace()); }
@Override public final String getName() { return _propName.getSimpleName(); }