Java Code Examples for org.apache.commons.lang3.reflect.FieldUtils#getDeclaredField()
The following examples show how to use
org.apache.commons.lang3.reflect.FieldUtils#getDeclaredField() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringDocApp9Test.java From springdoc-openapi with Apache License 2.0 | 6 votes |
@BeforeEach void init() throws IllegalAccessException { Field convertersField2 = FieldUtils.getDeclaredField(ObjectMapper.class, "_mixIns", true); SimpleMixInResolver _mixIns = (SimpleMixInResolver) convertersField2.get(Json.mapper()); Field convertersField3 = FieldUtils.getDeclaredField(SimpleMixInResolver.class, "_localMixIns", true); Map<ClassKey, Class<?>> _localMixIns = (Map<ClassKey, Class<?>>) convertersField3.get(_mixIns); Iterator<Map.Entry<ClassKey, Class<?>>> it = _localMixIns.entrySet().iterator(); while (it.hasNext()) { Map.Entry<ClassKey, Class<?>> entry = it.next(); if (entry.getKey().toString().startsWith("org.springframework")) { springMixins.put(entry.getKey(), entry.getValue()); it.remove(); } } }
Example 2
Source File: InjectTransformManager.java From atlas with Apache License 2.0 | 6 votes |
/** * Update the parameters for the transformTask * * @param transformTask * @param consumedInputStreams * @param referencedInputStreams * @param outputStream */ private void updateTransformTaskConfig(TransformTask transformTask, @NonNull Collection<TransformStream> consumedInputStreams, @NonNull Collection<TransformStream> referencedInputStreams, @Nullable IntermediateStream outputStream) throws IllegalAccessException { Field consumedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class, "consumedInputStreams", true); Field referencedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class, "referencedInputStreams", true); Field outputStreamField = FieldUtils.getDeclaredField(StreamBasedTask.class, "outputStream", true); if (null == consumedInputStreamsField || null == referencedInputStreamsField || null == outputStreamField) { throw new StopExecutionException( "The TransformTask does not has field with name: consumedInputStreams or referencedInputStreams or outputStream! Plugin version does not support!"); } consumedInputStreamsField.set(transformTask, consumedInputStreams); referencedInputStreamsField.set(transformTask, referencedInputStreams); outputStreamField.set(transformTask, outputStream); }
Example 3
Source File: InjectTransformManager.java From atlas with Apache License 2.0 | 6 votes |
/** * Gets the parameters of a transformTask * * @param transformTask * @return * @throws IllegalAccessException */ private TransformTaskParam getTransformParam(TransformTask transformTask) throws IllegalAccessException { TransformTaskParam transformTaskParam = new TransformTaskParam(); Field consumedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class, "consumedInputStreams", true); Field referencedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class, "referencedInputStreams", true); Field outputStreamField = FieldUtils.getDeclaredField(StreamBasedTask.class, "outputStream", true); if (null == consumedInputStreamsField || null == referencedInputStreamsField || null == outputStreamField) { throw new StopExecutionException( "The TransformTask does not has field with name: consumedInputStreams or referencedInputStreams or outputStream! Plugin version does not support!"); } transformTaskParam.consumedInputStreams = (Collection<TransformStream>) consumedInputStreamsField .get(transformTask); transformTaskParam.referencedInputStreams = (Collection<TransformStream>) referencedInputStreamsField .get(transformTask); transformTaskParam.outputStream = (IntermediateStream) outputStreamField.get(transformTask); return transformTaskParam; }
Example 4
Source File: ModelPersistorImpl.java From sling-whiteboard with Apache License 2.0 | 6 votes |
private static String getJcrPath(Object obj) { String path = (String) getAnnotatedValue(obj, Path.class); if (path != null) { return path; } try { Method pathGetter = MethodUtils.getMatchingMethod(obj.getClass(), "getPath"); if (pathGetter != null) { return (String) MethodUtils.invokeMethod(obj, "getPath"); } Field pathField = FieldUtils.getDeclaredField(obj.getClass(), "path"); if (pathField != null) { return (String) FieldUtils.readField(pathField, obj, true); } } catch (IllegalArgumentException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { LOGGER.warn("exception caught", ex); } LOGGER.warn("Object of type {} does NOT contain a Path attribute or a path property - multiple instances may conflict", obj.getClass()); return null; }
Example 5
Source File: ModelConverterRegistrar.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Gets registered converter same as. * * @param modelConverter the model converter * @return the registered converter same as */ private Optional<ModelConverter> getRegisteredConverterSameAs(ModelConverter modelConverter) { try { Field convertersField = FieldUtils.getDeclaredField(ModelConverters.class, "converters", true); List<ModelConverter> modelConverters = (List<ModelConverter>) convertersField.get(modelConvertersInstance); return modelConverters.stream() .filter(registeredModelConverter -> isSameConverter(registeredModelConverter, modelConverter)) .findFirst(); } catch (IllegalAccessException exception) { LOGGER.warn(exception.getMessage()); } return Optional.empty(); }
Example 6
Source File: QuerydslPredicateOperationCustomizer.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Gets field values. * * @param instance the instance * @param fieldName the field name * @return the field values */ private Set<String> getFieldValues(QuerydslBindings instance, String fieldName) { try { Field field = FieldUtils.getDeclaredField(instance.getClass(),fieldName,true); return (Set<String>) field.get(instance); } catch (IllegalAccessException e) { LOGGER.warn(e.getMessage()); } return Collections.emptySet(); }
Example 7
Source File: QuerydslPredicateOperationCustomizer.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Gets path spec. * * @param instance the instance * @param fieldName the field name * @return the path spec */ private Map<String, Object> getPathSpec(QuerydslBindings instance, String fieldName) { try { Field field = FieldUtils.getDeclaredField(instance.getClass(),fieldName,true); return (Map<String, Object>) field.get(instance); } catch (IllegalAccessException e) { LOGGER.warn(e.getMessage()); } return Collections.emptyMap(); }
Example 8
Source File: QuerydslPredicateOperationCustomizer.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Gets path from path spec. * * @param instance the instance * @return the path from path spec */ private Optional<Path<?>> getPathFromPathSpec(Object instance) { try { if (instance == null) { return Optional.empty(); } Field field = FieldUtils.getDeclaredField(instance.getClass(),"path",true); return (Optional<Path<?>>) field.get(instance); } catch (IllegalAccessException e) { LOGGER.warn(e.getMessage()); } return Optional.empty(); }
Example 9
Source File: SpringDocApp9Test.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@AfterEach private void clean() throws IllegalAccessException { Field convertersField2 = FieldUtils.getDeclaredField(ObjectMapper.class, "_mixIns", true); SimpleMixInResolver _mixIns = (SimpleMixInResolver) convertersField2.get(Json.mapper()); Field convertersField3 = FieldUtils.getDeclaredField(SimpleMixInResolver.class, "_localMixIns", true); Map<ClassKey, Class<?>> _localMixIns = (Map<ClassKey, Class<?>>) convertersField3.get(_mixIns); _localMixIns.putAll(springMixins); }
Example 10
Source File: BW_Util.java From bartworks with MIT License | 5 votes |
@SuppressWarnings("unchecked") public static List<IRecipe> getGTBufferedRecipeList() throws SecurityException, IllegalArgumentException, IllegalAccessException{ if (sBufferedRecipeList == null) { sBufferedRecipeList = FieldUtils.getDeclaredField(GT_ModHandler.class,"sBufferRecipeList",true); } if (sBufferedRecipeList == null) { sBufferedRecipeList = FieldUtils.getField(GT_ModHandler.class,"sBufferRecipeList",true); } return (List<IRecipe>) sBufferedRecipeList.get(null); }
Example 11
Source File: QualityCheckStep.java From mojito with Apache License 2.0 | 5 votes |
/** * Initializes the QualityCheckSession defined in the parent step, using Reflection */ public QualityCheckStep() { super(); try { parentSession = new QualityCheckSession(); // replace the "session" with our own version Field field = FieldUtils.getDeclaredField(this.getClass().getSuperclass(), "session", true); field.set(this, parentSession); } catch (IllegalAccessException e) { logger.error("Cannot replace the QualityCheckSession with Reflection"); } }
Example 12
Source File: XmbgMojoUnitTest.java From dolphin with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected boolean checkPlugin(Class<?> clazz, Context context){ Field field = FieldUtils.getDeclaredField(Context.class,"pluginConfigurations",true); try { List<PluginConfiguration> pluginConfigurations = (List<PluginConfiguration>) field.get(context); for(PluginConfiguration pluginConfiguration : pluginConfigurations){ if(pluginConfiguration.getConfigurationType().equals(clazz.getTypeName())){ return true; } } } catch (IllegalAccessException e) { e.printStackTrace(); } return false; }
Example 13
Source File: DefaultAnnotationToStringBuilderTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * Test 1. */ @Test public void test1(){ Field field = FieldUtils.getDeclaredField(DangaMemCachedConfig.class, "serverList", true); Alias alias = field.getAnnotation(Alias.class); assertEquals( "@com.feilong.core.bean.Alias(name=memcached.serverlist, sampleValue=172.20.31.23:11211,172.20.31.22:11211)", annotationToStringBuilder.build(alias)); }
Example 14
Source File: Fields.java From junit-servers with MIT License | 5 votes |
/** * Read private static field on given class. * * @param klass The class. * @param name The field name. * @param <T> Type of returned value. * @return The field value. */ public static <T> T readPrivateStatic(Class<?> klass, String name) { Field field = FieldUtils.getDeclaredField(klass, name, true); FieldUtils.removeFinalModifier(field); try { @SuppressWarnings("unchecked") T value = (T) FieldUtils.readStaticField(field, true); return value; } catch (IllegalAccessException ex) { throw new AssertionError(ex); } }
Example 15
Source File: StandardOidcIdentityProviderTest.java From nifi with Apache License 2.0 | 5 votes |
private StandardOidcIdentityProvider createOidcProviderWithAdditionalScopes(String... additionalScopes) throws IllegalAccessException { final StandardOidcIdentityProvider provider = mock(StandardOidcIdentityProvider.class); NiFiProperties properties = createNiFiPropertiesMockWithAdditionalScopes(Arrays.asList(additionalScopes)); Field propertiesField = FieldUtils.getDeclaredField(StandardOidcIdentityProvider.class, "properties", true); propertiesField.set(provider, properties); when(provider.isOidcEnabled()).thenReturn(true); when(provider.getScope()).thenCallRealMethod(); return provider; }
Example 16
Source File: ReflectionUtils.java From confucius-commons with Apache License 2.0 | 3 votes |
/** * Assert Field type match * * @param object * Object * @param fieldName * field name * @param expectedType * expected type * @throws IllegalArgumentException * if type is not matched */ public static void assertFieldMatchType(Object object, String fieldName, Class<?> expectedType) throws IllegalArgumentException { Class<?> type = object.getClass(); Field field = FieldUtils.getDeclaredField(type, fieldName, true); Class<?> fieldType = field.getType(); if (!expectedType.isAssignableFrom(fieldType)) { String message = String.format("The type[%s] of field[%s] in Class[%s] can't match expected type[%s]", fieldType.getName(), fieldName, type.getName(), expectedType.getName()); throw new IllegalArgumentException(message); } }