/** * Method that can be called to find if introspected class declares a static "valueOf" factory * method that returns an instance of introspected type, given one of acceptable types. * * @param expArgTypes Types that the matching single argument factory method can take: will also * accept super types of these types (ie. arg just has to be assignable from expArgType) */ public Method findFactoryMethod(Class<?>... expArgTypes) { // So, of all single-arg static methods: for (AnnotatedMethod am : _classInfo.getStaticMethods()) { if (isFactoryMethod(am)) { // And must take one of expected arg types (or supertype) Class<?> actualArgType = am.getParameterClass(0); for (Class<?> expArgType : expArgTypes) { // And one that matches what we would pass in if (actualArgType.isAssignableFrom(expArgType)) { return am.getAnnotated(); } } } } return null; }
/** * Method used to locate the method of introspected class that implements {@link * sh.calaba.org.codehaus.jackson.annotate.JsonAnySetter}. If no such method exists null is * returned. If more than one are found, an exception is thrown. Additional checks are also made * to see that method signature is acceptable: needs to take 2 arguments, first one String or * Object; second any can be any type. */ @Override public AnnotatedMethod findAnySetter() throws IllegalArgumentException { if (_anySetterMethod != null) { /* Also, let's be somewhat strict on how field name is to be * passed; String, Object make sense, others not * so much. */ /* !!! 18-May-2009, tatu: how about enums? Can add support if * requested; easy enough for devs to add support within * method. */ Class<?> type = _anySetterMethod.getParameterClass(0); if (type != String.class && type != Object.class) { throw new IllegalArgumentException( "Invalid 'any-setter' annotation on method " + _anySetterMethod.getName() + "(): first argument not of type String or Object, but " + type.getName()); } } return _anySetterMethod; }