/** * Method that can be called to modify access rights, by calling * {@link java.lang.reflect.AccessibleObject#setAccessible} on * the underlying annotated element. */ public final void fixAccess() { ClassUtil.checkAndFixAccess(getMember()); }
protected AnnotatedWithParams verifyNonDup(AnnotatedWithParams newOne, AnnotatedWithParams oldOne, String type) { if (oldOne != null) { // important: ok to override factory with constructor; but not within same type, so: if (oldOne.getClass() == newOne.getClass()) { throw new IllegalArgumentException("Conflicting "+type+" creators: already had "+oldOne+", encountered "+newOne); } } if (_canFixAccess) { ClassUtil.checkAndFixAccess((Member) newOne.getAnnotated()); } return newOne; } }
public static <T> Constructor<T> findConstructor(Class<T> cls, boolean canFixAccess) throws IllegalArgumentException { try { Constructor<T> ctor = cls.getDeclaredConstructor(); if (canFixAccess) { checkAndFixAccess(ctor); } else { // Has to be public... if (!Modifier.isPublic(ctor.getModifiers())) { throw new IllegalArgumentException("Default constructor for "+cls.getName()+" is not accessible (non-public?): not allowed to try modify access via Reflection: can not instantiate type"); } } return ctor; } catch (NoSuchMethodException e) { ; } catch (Exception e) { ClassUtil.unwrapAndThrowAsIAE(e, "Failed to find default constructor of class "+cls.getName()+", problem: "+e.getMessage()); } return null; }
/** * Factory method used when Enum instances are to be deserialized * using a creator (static factory method) * * @return Deserializer based on given factory method, if type was suitable; * null if type can not be used */ public static JsonDeserializer<?> deserializerForCreator(DeserializationConfig config, Class<?> enumClass, AnnotatedMethod factory) { // note: caller has verified there's just one arg; but we must verify its type Class<?> raw = factory.getParameterClass(0); if (raw == String.class) { raw = null; } else if (raw == Integer.TYPE || raw == Integer.class) { raw = Integer.class; } else if (raw == Long.TYPE || raw == Long.class) { raw = Long.class; } else { throw new IllegalArgumentException("Parameter #0 type for factory method ("+factory +") not suitable, must be java.lang.String or int/Integer/long/Long"); } if (config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { ClassUtil.checkAndFixAccess(factory.getMember()); } return new FactoryBasedDeserializer(enumClass, factory, raw); }
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; } }
ClassUtil.checkAndFixAccess(factory.getMember());
if (paramTypes.length == 1 && paramTypes[0] == enclosing) { if (config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { ClassUtil.checkAndFixAccess(ctor);
if (defaultCtor != null) { if (fixAccess) { ClassUtil.checkAndFixAccess(defaultCtor.getAnnotated());
/** * Method that can be called to modify access rights, by calling * {@link java.lang.reflect.AccessibleObject#setAccessible} on * the underlying annotated element. */ public final void fixAccess() { ClassUtil.checkAndFixAccess(getMember()); }
protected AnnotatedWithParams verifyNonDup(AnnotatedWithParams newOne, AnnotatedWithParams oldOne, String type) { if (oldOne != null) { // important: ok to override factory with constructor; but not within same type, so: if (oldOne.getClass() == newOne.getClass()) { throw new IllegalArgumentException("Conflicting "+type+" creators: already had "+oldOne+", encountered "+newOne); } } if (_canFixAccess) { ClassUtil.checkAndFixAccess((Member) newOne.getAnnotated()); } return newOne; } }
public static <T> Constructor<T> findConstructor(Class<T> cls, boolean canFixAccess) throws IllegalArgumentException { try { Constructor<T> ctor = cls.getDeclaredConstructor(); if (canFixAccess) { checkAndFixAccess(ctor); } else { // Has to be public... if (!Modifier.isPublic(ctor.getModifiers())) { throw new IllegalArgumentException("Default constructor for "+cls.getName()+" is not accessible (non-public?): not allowed to try modify access via Reflection: can not instantiate type"); } } return ctor; } catch (NoSuchMethodException e) { ; } catch (Exception e) { ClassUtil.unwrapAndThrowAsIAE(e, "Failed to find default constructor of class "+cls.getName()+", problem: "+e.getMessage()); } return null; }
/** * Factory method used when Enum instances are to be deserialized * using a creator (static factory method) * * @return Deserializer based on given factory method, if type was suitable; * null if type can not be used */ public static JsonDeserializer<?> deserializerForCreator(DeserializationConfig config, Class<?> enumClass, AnnotatedMethod factory) { // note: caller has verified there's just one arg; but we must verify its type Class<?> raw = factory.getParameterClass(0); if (raw == String.class) { raw = null; } else if (raw == Integer.TYPE || raw == Integer.class) { raw = Integer.class; } else if (raw == Long.TYPE || raw == Long.class) { raw = Long.class; } else { throw new IllegalArgumentException("Parameter #0 type for factory method ("+factory +") not suitable, must be java.lang.String or int/Integer/long/Long"); } if (config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { ClassUtil.checkAndFixAccess(factory.getMember()); } return new FactoryBasedDeserializer(enumClass, factory, raw); }
ClassUtil.checkAndFixAccess(m);
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; } }
ClassUtil.checkAndFixAccess(factory.getMember());
if (paramTypes.length == 1 && paramTypes[0] == enclosing) { if (config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { ClassUtil.checkAndFixAccess(ctor);
/** * Method that can be called to modify access rights, by calling * {@link java.lang.reflect.AccessibleObject#setAccessible} on * the underlying annotated element. */ public void fixAccess() { ClassUtil.checkAndFixAccess(_field); }
/** * Method that can be called to modify access rights, by calling * {@link java.lang.reflect.AccessibleObject#setAccessible} on * the underlying annotated element. */ public final void fixAccess() { ClassUtil.checkAndFixAccess(getMember()); }
if (defaultCtor != null) { if (fixAccess) { ClassUtil.checkAndFixAccess(defaultCtor.getAnnotated());