@Override public Object getValue(Object pojo) throws UnsupportedOperationException { throw new UnsupportedOperationException("Cannot call getValue() on constructor parameter of " +getDeclaringClass().getName()); }
throws JsonMappingException final DeserializationConfig config = ctxt.getConfig(); AnnotatedClass ac = beanDesc.getClassInfo(); Object instDef = ctxt.getAnnotationIntrospector().findValueInstantiator(ac); if (instDef != null) { instantiator = _valueInstantiatorInstance(config, ac, instDef); ctxt.reportBadTypeDefinition(beanDesc, "Broken registered ValueInstantiators (of type %s): returned null ValueInstantiator", insts.getClass().getName()); final AnnotatedWithParams ctor = nonAnnotatedParam.getOwner(); throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex() +" of constructor "+ctor+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator");
@Override public <A extends Annotation> A getAnnotation(Class<A> acls) { if (_annotated == null) { return null; } return _annotated.getAnnotation(acls); }
@Override public PropertyName findConstructorName(AnnotatedParameter p) { AnnotatedWithParams ctor = p.getOwner(); if (ctor != null) { ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class); if (props != null) { String[] names = props.value(); int ix = p.getIndex(); if (ix < names.length) { return PropertyName.construct(names[ix]); } } } return null; } }
for (BeanPropertyDefinition propDef : beanDesc.findProperties()) { Iterator<AnnotatedParameter> it = propDef.getConstructorParameters(); while (it.hasNext()) { AnnotatedParameter param = it.next(); AnnotatedWithParams owner = param.getOwner(); BeanPropertyDefinition[] defs = result.get(owner); final int index = param.getIndex(); result = new LinkedHashMap<AnnotatedWithParams,BeanPropertyDefinition[]>(); defs = new BeanPropertyDefinition[owner.getParameterCount()]; result.put(owner, defs); } else { if (defs[index] != null) { ctxt.reportBadTypeDefinition(beanDesc, "Conflict: parameter #%d of %s bound to more than one property; %s vs %s", index, owner, defs[index], propDef);
private static <T extends Annotation> AnnotationFound<T> getAnnotation(BeanPropertyDefinition property, Class<T> annotation) { String annotationName = "@" + annotation.getSimpleName(); if ( property.hasConstructorParameter() ) { AnnotatedParameter parameter = property.getConstructorParameter(); T constructorAnnotation = parameter.getAnnotation(annotation); if ( constructorAnnotation != null ) { AnnotationFound<T> found = new AnnotationFound<>(); found.annotation = constructorAnnotation; found.foundMessage = annotationName + " on constructor parameter '" + parameter.getRawType().getName() + " " + parameter.getName() + "'"; return found; if ( property.hasField() ) { T fieldAnnotation = property.getField().getAnnotation(annotation); if ( fieldAnnotation != null ) {
throws JsonMappingException final DeserializationConfig config = ctxt.getConfig(); for (AnnotatedMethod factory : beanDesc.getFactoryMethods()) { final boolean isCreator = intr.hasCreatorAnnotation(factory); final int argCount = factory.getParameterCount(); final AnnotatedParameter param = factory.getParameter(i); BeanPropertyDefinition propDef = (propDefs == null) ? null : propDefs[i]; Object injectId = intr.findInjectableValueId(param); final PropertyName name = (propDef == null) ? null : propDef.getFullName(); if (propDef != null && propDef.isExplicitlyNamed()) { ++explicitNameCount; properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId); continue; NameTransformer unwrapper = intr.findUnwrappingNameTransformer(param); if (unwrapper != null) { properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null); if (name != null && !name.isEmpty()) { ++implicitNameCount; properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId); throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex() +" of factory method "+factory+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator");
throws JsonMappingException final DeserializationConfig config = ctxt.getConfig(); final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector(); PropertyMetadata metadata; metadata = PropertyMetadata.STD_REQUIRED_OR_OPTIONAL; } else { Boolean b = intr.hasRequiredMarker(param); String desc = intr.findPropertyDescription(param); Integer idx = intr.findPropertyIndex(param); String def = intr.findPropertyDefaultValue(param); metadata = PropertyMetadata.construct(b, desc, idx, def); JavaType type = resolveMemberAndTypeAnnotations(ctxt, param, param.getType()); BeanProperty.Std property = new BeanProperty.Std(name, type, intr.findWrapperName(param), param, metadata); typeDeser, beanDesc.getClassAnnotations(), param, index, injectableValueId, metadata); JsonDeserializer<?> deser = findDeserializerFromAnnotation(ctxt, param); deser = ctxt.handlePrimaryContextualization(deser, prop, type); prop = prop.withValueDeserializer(deser);
AnnotatedConstructor defaultCtor = beanDesc.findDefaultConstructor(); if (defaultCtor != null) { if (!creators.hasDefaultCreator() || intr.hasCreatorAnnotation(defaultCtor)) { creators.setDefaultCreator(defaultCtor); for (AnnotatedConstructor ctor : beanDesc.getConstructors()) { final boolean isCreator = intr.hasCreatorAnnotation(ctor); BeanPropertyDefinition[] propDefs = creatorParams.get(ctor); final int argCount = ctor.getParameterCount(); PropertyName name = (argDef == null) ? null : argDef.getFullName(); AnnotatedParameter arg = ctor.getParameter(0); properties[0] = constructCreatorProperty(ctxt, beanDesc, name, 0, arg, intr.findInjectableValueId(arg)); creators.addPropertyCreator(ctor, isCreator, properties); } else { if (name != null && !name.isEmpty()) { ++implicitNameCount; properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId); } else { // otherwise, epic fail int ix = nonAnnotatedParam.getIndex(); if ((ix == 0) && ClassUtil.isNonStaticInnerClass(ctor.getDeclaringClass())) { throw new IllegalArgumentException("Non-static inner classes like "
Map<String,AnnotatedMember> refs = beanDesc.findBackReferenceProperties(); if (refs != null) { for (Map.Entry<String, AnnotatedMember> en : refs.entrySet()) { ctxt.reportBadTypeDefinition(beanDesc, "Can not bind back references as Creator parameters: type %s (reference '%s', parameter index #%d)", beanDesc.getBeanClass().getName(), name, ((AnnotatedParameter) m).getIndex()); SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct( ctxt.getConfig(), m, PropertyName.construct(name)); builder.addBackReferenceProperty(name, constructSettableProperty(ctxt, beanDesc, propDef, type));
throws JsonMappingException final DeserializationConfig config = ctxt.getConfig(); final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector(); PropertyMetadata metadata; metadata = PropertyMetadata.STD_REQUIRED_OR_OPTIONAL; } else { Boolean b = intr.hasRequiredMarker(param); boolean req = (b != null && b.booleanValue()); String desc = intr.findPropertyDescription(param); Integer idx = intr.findPropertyIndex(param); String def = intr.findPropertyDefaultValue(param); metadata = PropertyMetadata.construct(req, desc, idx, def); JavaType t0 = config.getTypeFactory().constructType(param.getParameterType(), beanDesc.bindingsForBeanType()); BeanProperty.Std property = new BeanProperty.Std(name, t0, intr.findWrapperName(param), beanDesc.getClassAnnotations(), param, metadata); JavaType type = resolveType(ctxt, beanDesc, t0, param); if (type != t0) { typeDeser, beanDesc.getClassAnnotations(), param, index, injectableValueId, metadata); if (deser != null) { deser = ctxt.handlePrimaryContextualization(deser, prop, type); prop = prop.withValueDeserializer(deser);
for (AnnotatedMethod factory : beanDesc.getFactoryMethods()) { JsonCreator.Mode creatorMode = intr.findCreatorAnnotation(ctxt.getConfig(), factory); final int argCount = factory.getParameterCount(); if (creatorMode == null) { final AnnotatedParameter param = factory.getParameter(i); BeanPropertyDefinition propDef = (propDefs == null) ? null : propDefs[i]; JacksonInject.Value injectable = intr.findInjectableValue(param); final PropertyName name = (propDef == null) ? null : propDef.getFullName(); if (propDef != null && propDef.isExplicitlyNamed()) { ++explicitNameCount; properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectable); continue; NameTransformer unwrapper = intr.findUnwrappingNameTransformer(param); if (unwrapper != null) { _reportUnwrappedCreatorProperty(ctxt, beanDesc, param); ctxt.reportBadTypeDefinition(beanDesc, "Argument #%d of factory method %s has no property name annotation; must have name when multiple-parameter constructor annotated as Creator", nonAnnotatedParam.getIndex(), factory);
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);
throws JsonMappingException final DeserializationConfig config = ctxt.getConfig(); for (AnnotatedMethod factory : beanDesc.getFactoryMethods()) { boolean isCreator = intr.hasCreatorAnnotation(factory); int argCount = factory.getParameterCount(); PropertyName pn = (param == null) ? null : intr.findNameForDeserialization(param); String name = (pn == null) ? null : pn.getSimpleName(); Object injectId = intr.findInjectableValueId(param); AnnotatedParameter param = factory.getParameter(i); PropertyName pn = (param == null) ? null : intr.findNameForDeserialization(param); String name = (pn == null) ? null : pn.getSimpleName(); Object injectId = intr.findInjectableValueId(param); if (name != null && name.length() > 0) { throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex() +" of factory method "+factory+" has no property name annotation; must have name when multiple-paramater constructor annotated as Creator");
AnnotatedConstructor defaultCtor = beanDesc.findDefaultConstructor(); if (defaultCtor != null) { if (!creators.hasDefaultCreator() || intr.hasCreatorAnnotation(defaultCtor)) { creators.setDefaultCreator(defaultCtor); for (AnnotatedConstructor ctor : beanDesc.getConstructors()) { int argCount = ctor.getParameterCount(); boolean isCreator = intr.hasCreatorAnnotation(ctor); boolean isVisible = vchecker.isCreatorVisible(ctor); for (int i = 0; i < argCount; ++i) { AnnotatedParameter param = ctor.getParameter(i); PropertyName pn = (param == null) ? null : intr.findNameForDeserialization(param); String name = (pn == null) ? null : pn.getSimpleName(); Object injectId = intr.findInjectableValueId(param); if (name != null && name.length() > 0) { throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex()+" of constructor "+ctor+" has no property name annotation; must have name when multiple-paramater constructor annotated as Creator");
protected void _reportUnwrappedCreatorProperty(DeserializationContext ctxt, BeanDescription beanDesc, AnnotatedParameter param) throws JsonMappingException { ctxt.reportBadDefinition(beanDesc.getType(), String.format( "Cannot define Creator parameter %d as `@JsonUnwrapped`: combination not yet supported", param.getIndex())); }
final int argCount = ctor.getParameterCount(); SettableBeanProperty[] properties = new SettableBeanProperty[argCount]; for (int i = 0; i < argCount; ++i) { final AnnotatedParameter param = ctor.getParameter(i); final PropertyName name = _findParamName(param, intr); if (name == null || name.isEmpty()) { continue main_loop; properties[i] = constructCreatorProperty(ctxt, beanDesc, name, param.getIndex(), if (!bbd.hasProperty(pn)) { BeanPropertyDefinition newDef = SimpleBeanPropertyDefinition.construct( ctxt.getConfig(), prop.getMember(), pn); bbd.addProperty(newDef);
throws JsonMappingException final DeserializationConfig config = ctxt.getConfig(); for (AnnotatedMethod factory : beanDesc.getFactoryMethods()) { int argCount = factory.getParameterCount(); if (argCount < 1) { continue; boolean isCreator = intr.hasCreatorAnnotation(factory); String name = intr.findDeserializationName(param); Object injectId = intr.findInjectableValueId(param); throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex() +" of factory method "+factory+" has no property name annotation; must have name when multiple-paramater constructor annotated as Creator");
@Override public PropertyName findNameForDeserialization(Annotated a) { if (a instanceof AnnotatedParameter) { AnnotatedParameter ap = (AnnotatedParameter) a; if (ap.getOwner() instanceof AnnotatedConstructor) { AnnotatedConstructor ac = (AnnotatedConstructor) ap.getOwner(); Constructor<?> c = ac.getAnnotated(); ConstructorProperties properties = c.getAnnotation(ConstructorProperties.class); if (properties != null) { String[] names = properties.value(); int index = ap.getIndex(); if (index < names.length) { return new PropertyName( names[index] ); } } } } // Default return super.findNameForDeserialization(a); } }
throws JsonMappingException final DeserializationConfig config = ctxt.getConfig(); JavaType t0 = config.getTypeFactory().constructType(param.getParameterType(), beanDesc.bindingsForBeanType()); BeanProperty.Std property = new BeanProperty.Std(name, t0, beanDesc.getClassAnnotations(), param); JavaType type = resolveType(ctxt, beanDesc, t0, param); if (type != t0) { beanDesc.getClassAnnotations(), param, index, injectableValueId); if (deser != null) { prop = prop.withValueDeserializer(deser);