Here are the examples of the java api org.springframework.util.ReflectionUtils.setField() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
68 Examples
19
View Source File : BaseRepositoryImpl.java
License : Eclipse Public License 1.0
Project Creator : zhaoqilong3031
License : Eclipse Public License 1.0
Project Creator : zhaoqilong3031
public static void main(String[] args) {
Customer target = new Customer();
target.setId("1");
Customer des = new Customer();
Field[] fields = Customer.clreplaced.getDeclaredFields();
// ReflectionUtils.getAllDeclaredMethods(leafClreplaced)
for (Field field : fields) {
ReflectionUtils.makeAccessible(field);
Object v = ReflectionUtils.getField(field, target);
System.err.println(field.getName() + "++ " + v);
ReflectionUtils.setField(field, des, v);
}
System.err.println(des.getId());
// ReflectionUtils.getAllDeclaredMethods(enreplacedyClreplaced);
}
19
View Source File : MockitoPostProcessor.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private void inject(Field field, Object target, String beanName) {
try {
field.setAccessible(true);
replacedert.state(ReflectionUtils.getField(field, target) == null, () -> "The field " + field + " cannot have an existing value");
Object bean = this.beanFactory.getBean(beanName, field.getType());
ReflectionUtils.setField(field, target, bean);
} catch (Throwable ex) {
throw new BeanCreationException("Could not inject field: " + field, ex);
}
}
19
View Source File : ReflectUtil.java
License : MIT License
Project Creator : yizzuide
License : MIT License
Project Creator : yizzuide
/**
* 设置对象的值
* @param target 对象
* @param props 属性Map
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void setField(Object target, Map<String, Object> props) {
for (Map.Entry<String, Object> entry : props.entrySet()) {
Field field = ReflectionUtils.findField(target.getClreplaced(), entry.getKey());
if (field == null)
continue;
ReflectionUtils.makeAccessible(field);
// String -> Enum
if (Enum.clreplaced.isreplacedignableFrom(field.getType()) && entry.getValue() instanceof String) {
ReflectionUtils.setField(field, target, Enum.valueOf((Clreplaced<? extends Enum>) field.getType(), (String) entry.getValue()));
} else if (Long.clreplaced.isreplacedignableFrom(field.getType()) && entry.getValue() instanceof Integer) {
ReflectionUtils.setField(field, target, Long.valueOf(String.valueOf(entry.getValue())));
} else if (List.clreplaced.isreplacedignableFrom(field.getType()) && entry.getValue() instanceof Map) {
ReflectionUtils.setField(field, target, new ArrayList(((LinkedHashMap) entry.getValue()).values()));
} else {
ReflectionUtils.setField(field, target, entry.getValue());
}
}
}
19
View Source File : ThinJarAppWrapper.java
License : Apache License 2.0
Project Creator : spring-projects-experimental
License : Apache License 2.0
Project Creator : spring-projects-experimental
private void setField(Clreplaced<?> type, String name, Object value) {
Field field = ReflectionUtils.findField(type, name);
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, null, value);
}
19
View Source File : SpringBootstrap.java
License : Apache License 2.0
Project Creator : hank-cp
License : Apache License 2.0
Project Creator : hank-cp
private void hackBeanFactory(ApplicationContext applicationContext) {
if (pluginClreplacedLoader instanceof SpringBootPluginClreplacedLoader) {
if (pluginFirstClreplacedes != null) {
((SpringBootPluginClreplacedLoader) pluginClreplacedLoader).setPluginFirstClreplacedes(pluginFirstClreplacedes);
}
if (pluginOnlyResources != null) {
((SpringBootPluginClreplacedLoader) pluginClreplacedLoader).setPluginOnlyResources(pluginOnlyResources);
}
}
BeanFactory beanFactory = new PluginListableBeanFactory(pluginClreplacedLoader);
Field beanFactoryField = ReflectionUtils.findField(applicationContext.getClreplaced(), "beanFactory");
if (beanFactoryField != null) {
beanFactoryField.setAccessible(true);
ReflectionUtils.setField(beanFactoryField, applicationContext, beanFactory);
}
}
18
View Source File : Message.java
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus
public static CodedInputStream getCodedInputStream(byte[] data) {
CodedInputStream codedInputStream = CodedInputStream.newInstance(data);
if (isFilter()) {
ReflectionUtils.setField(field, codedInputStream, true);
}
return codedInputStream;
}
18
View Source File : IntegrationTestsSupport.java
License : Apache License 2.0
Project Creator : spring-projects
License : Apache License 2.0
Project Creator : spring-projects
// TODO: Remove once GEODE-7157 (https://issues.apache.org/jira/browse/GEODE-7157) is fixed!
// Do the job of Apache Geode & VMware GemFire since it cannot do its own damn job!
@BeforeClreplaced
public static void closeAnySslConfigurationBeforeTestExecution() {
// SSLConfigurationFactory.close();
synchronized (SSLConfigurationFactory.clreplaced) {
try {
Field instance = ReflectionUtils.findField(SSLConfigurationFactory.clreplaced, "instance", SSLConfigurationFactory.clreplaced);
Optional.ofNullable(instance).ifPresent(field -> {
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, null, null);
});
} catch (Throwable ignore) {
// Not much we can do about it now!
}
}
}
18
View Source File : StateMachineTests.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
private static void setId(Clreplaced<?> clazz, Object instance, String fieldName, Object value) {
try {
Field field = ReflectionUtils.findField(clazz, fieldName);
field.setAccessible(true);
int modifiers = field.getModifiers();
Field modifierField = field.getClreplaced().getDeclaredField("modifiers");
modifiers = modifiers & ~Modifier.FINAL;
modifierField.setAccessible(true);
modifierField.setInt(field, modifiers);
ReflectionUtils.setField(field, instance, value);
} catch (ReflectiveOperationException e) {
throw new IllegalArgumentException(e);
}
}
18
View Source File : GovernedAssetClientClientTest.java
License : Apache License 2.0
Project Creator : odpi
License : Apache License 2.0
Project Creator : odpi
@Before
public void before() throws InvalidParameterException {
MockitoAnnotations.initMocks(this);
governedreplacedetClient = new GovernedreplacedetClient(SERVER_NAME, SERVER_URL);
Field connectorField = ReflectionUtils.findField(GovernedreplacedetClient.clreplaced, "clientConnector");
if (connectorField != null) {
connectorField.setAccessible(true);
ReflectionUtils.setField(connectorField, governedreplacedetClient, connector);
connectorField.setAccessible(false);
}
}
18
View Source File : GlossaryViewClientTest.java
License : Apache License 2.0
Project Creator : odpi
License : Apache License 2.0
Project Creator : odpi
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
underTest = new GlossaryViewClient(SERVER_NAME, SERVER_PLATFORM_URL, USER_ID, USER_PreplacedWORD);
Field connectorField = ReflectionUtils.findField(GlossaryViewClient.clreplaced, "clientConnector");
connectorField.setAccessible(true);
ReflectionUtils.setField(connectorField, underTest, connector);
connectorField.setAccessible(false);
response = new GlossaryViewEnreplacedyDetailResponse();
glossaries.add(createGlossaryViewEnreplacedyDetail(GLOSSARY, "glossary-01"));
glossaries.add(createGlossaryViewEnreplacedyDetail(GLOSSARY, "glossary-02"));
glossaries.add(createGlossaryViewEnreplacedyDetail(GLOSSARY, "glossary-03"));
categories.add(createGlossaryViewEnreplacedyDetail(CATEGORY, "category-01"));
categories.add(createGlossaryViewEnreplacedyDetail(CATEGORY, "category-02"));
categories.add(createGlossaryViewEnreplacedyDetail(CATEGORY, "category-03"));
categories.add(createGlossaryViewEnreplacedyDetail(CATEGORY, "category-04"));
categories.add(createGlossaryViewEnreplacedyDetail(CATEGORY, "category-05"));
terms.add(createGlossaryViewEnreplacedyDetail(TERM, "term-01"));
terms.add(createGlossaryViewEnreplacedyDetail(TERM, "term-02"));
terms.add(createGlossaryViewEnreplacedyDetail(TERM, "term-03"));
terms.add(createGlossaryViewEnreplacedyDetail(TERM, "term-04"));
terms.add(createGlossaryViewEnreplacedyDetail(TERM, "term-05"));
terms.add(createGlossaryViewEnreplacedyDetail(TERM, "term-06"));
terms.add(createGlossaryViewEnreplacedyDetail(TERM, "term-07"));
externalGlossaryLink = createGlossaryViewEnreplacedyDetail(EXTERNAL_GLOSSARY_LINK, "external-glossary-link-01");
}
18
View Source File : AssetCatalogServiceTest.java
License : Apache License 2.0
Project Creator : odpi
License : Apache License 2.0
Project Creator : odpi
@Before
public void before() {
MockitoAnnotations.initMocks(this);
Field instanceHandlerField = ReflectionUtils.findField(replacedetCatalogRESTService.clreplaced, "instanceHandler");
if (instanceHandlerField != null) {
instanceHandlerField.setAccessible(true);
ReflectionUtils.setField(instanceHandlerField, replacedetCatalogRESTService, instanceHandler);
instanceHandlerField.setAccessible(false);
}
Field restExceptionHandlerField = ReflectionUtils.findField(replacedetCatalogRESTService.clreplaced, "restExceptionHandler");
if (restExceptionHandlerField != null) {
restExceptionHandlerField.setAccessible(true);
ReflectionUtils.setField(restExceptionHandlerField, replacedetCatalogRESTService, restExceptionHandler);
restExceptionHandlerField.setAccessible(false);
}
}
18
View Source File : AssetCatalogClientTest.java
License : Apache License 2.0
Project Creator : odpi
License : Apache License 2.0
Project Creator : odpi
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
replacedetCatalog = new replacedetCatalog(SERVER_NAME, SERVER_URL);
Field connectorField = ReflectionUtils.findField(replacedetCatalog.clreplaced, "clientConnector");
if (connectorField != null) {
connectorField.setAccessible(true);
ReflectionUtils.setField(connectorField, replacedetCatalog, connector);
connectorField.setAccessible(false);
}
}
18
View Source File : ReflectUtil.java
License : GNU Lesser General Public License v3.0
Project Creator : lets-mica
License : GNU Lesser General Public License v3.0
Project Creator : lets-mica
/**
* 重写 setField 的方法,用于处理 setAccessible 的问题
*
* @param field Field
* @param target Object
* @param value value
*/
public static void setField(Field field, @Nullable Object target, @Nullable Object value) {
makeAccessible(field);
ReflectionUtils.setField(field, target, value);
}
18
View Source File : RpcDefinitionPostProcessor.java
License : Apache License 2.0
Project Creator : joyrpc
License : Apache License 2.0
Project Creator : joyrpc
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
// 再次查找所有的Consumer注解,检查是否注入了。
processConsumerAnnotation(bean.getClreplaced(), (f, c) -> {
AbstractConsumerConfig<?> config = members.get(f);
if (config != null) {
ReflectionUtils.makeAccessible(f);
ReflectionUtils.setField(f, bean, config.proxy());
}
}, (m, c) -> {
AbstractConsumerConfig<?> config = members.get(m);
if (config != null) {
ReflectionUtils.invokeMethod(m, bean, config.proxy());
}
});
return bean;
}
18
View Source File : VertxUtils.java
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
private static void enhanceVertx(String name, Vertx vertx) {
if (StringUtils.isEmpty(name)) {
return;
}
Field field = ReflectionUtils.findField(VertxImpl.clreplaced, "eventLoopThreadFactory");
field.setAccessible(true);
VertxThreadFactory eventLoopThreadFactory = (VertxThreadFactory) ReflectionUtils.getField(field, vertx);
field = ReflectionUtils.findField(eventLoopThreadFactory.getClreplaced(), "prefix");
field.setAccessible(true);
String prefix = (String) ReflectionUtils.getField(field, eventLoopThreadFactory);
ReflectionUtils.setField(field, eventLoopThreadFactory, name + "-" + prefix);
}
18
View Source File : ArchaiusUtils.java
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
@SuppressWarnings("unchecked")
public static void resetConfig() {
ReflectionUtils.setField(FIELD_INSTANCE, null, null);
ReflectionUtils.setField(FIELD_CUSTOM_CONFIGURATION_INSTALLED, null, false);
ReflectionUtils.setField(FIELD_CONFIG, null, null);
ReflectionUtils.setField(FIELD_INITIALIZED_WITH_DEFAULT_CONFIG, null, false);
ReflectionUtils.setField(FIELD_DYNAMIC_PROPERTY_SUPPORTIMPL, null, null);
((ConcurrentHashMap<String, DynamicProperty>) ReflectionUtils.getField(FIELD_DYNAMIC_PROPERTY_ALL_PROPS, null)).clear();
}
17
View Source File : PrivateHelper.java
License : Apache License 2.0
Project Creator : zhoutaoo
License : Apache License 2.0
Project Creator : zhoutaoo
/**
* @param instance 实例对象
* @param fieldName 成员变量名
* @param value 值
*/
public void setPrivateField(Object instance, String fieldName, Object value) {
Field signingKeyField = ReflectionUtils.findField(instance.getClreplaced(), fieldName);
ReflectionUtils.makeAccessible(signingKeyField);
ReflectionUtils.setField(signingKeyField, instance, value);
}
17
View Source File : ReflectUtil.java
License : MIT License
Project Creator : yizzuide
License : MIT License
Project Creator : yizzuide
/**
* 设置属性路径值
* @param target 目标对象
* @param fieldPath 属性路径
* @param value 值
* @since 3.7.1
*/
public static void setFieldPath(Object target, String fieldPath, Object value) {
Pair<Field, Object> fieldBundle = getFieldBundlePath(target, fieldPath);
if (fieldBundle == null) {
return;
}
ReflectionUtils.setField(fieldBundle.getKey(), fieldBundle.getValue(), value);
}
17
View Source File : ReflectUtils.java
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus
public static void setFieldValue(Object target, String fieldName, Object value) {
Field field = ReflectionUtils.findField(target.getClreplaced(), fieldName);
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, target, value);
}
17
View Source File : ESUtil.java
License : Apache License 2.0
Project Creator : newsettle
License : Apache License 2.0
Project Creator : newsettle
/**
* 通用的装换返回结果
*/
public <T> List<T> convertResponse(SearchResponse response, Clreplaced<T> clazz) {
List<T> list = Lists.newArrayList();
if (response != null && response.getHits() != null) {
String result = "";
T e = null;
Field idField = ReflectionUtils.findField(clazz, "id");
if (idField != null) {
ReflectionUtils.makeAccessible(idField);
}
for (SearchHit hit : response.getHits()) {
result = hit.getSourcereplacedtring();
if (StringUtils.hasText(result)) {
e = JSONObject.parseObject(result, clazz);
}
if (e != null) {
if (idField != null) {
ReflectionUtils.setField(idField, e, hit.getId());
}
list.add(e);
}
}
}
return list;
}
17
View Source File : SendFinanceTotalsActionTest.java
License : MIT License
Project Creator : InnovateUKGitHub
License : MIT License
Project Creator : InnovateUKGitHub
private void setFinanceTotalsToggle(boolean toggleValue) {
Field financeTotalsEnabledToggle = ReflectionUtils.findField(SendFinanceTotalsAction.clreplaced, "financeTotalsEnabled");
ReflectionUtils.makeAccessible(financeTotalsEnabledToggle);
ReflectionUtils.setField(financeTotalsEnabledToggle, sendFinanceTotalsAction, toggleValue);
}
17
View Source File : ConfigChangedListenerTest.java
License : Apache License 2.0
Project Creator : baidu
License : Apache License 2.0
Project Creator : baidu
private void setField(Object target, String field, Object value) {
Field f = ReflectionUtils.findField(target.getClreplaced(), field);
boolean accessible = f.isAccessible();
f.setAccessible(true);
ReflectionUtils.setField(f, target, value);
f.setAccessible(accessible);
}
17
View Source File : ExcelUtils.java
License : Apache License 2.0
Project Creator : 734839030
License : Apache License 2.0
Project Creator : 734839030
/**
* excel 导入 ,建议导入把模板都定义成string
*
* @param in
* 文件流
* @param rowBean
* 行对象
* @param column
* 列字段
* @return
* @throws IOException
* @throws IllegalAccessException
* @throws InstantiationException
*/
public static <T> List<T> doParse(InputStream in, Clreplaced<T> clazz, String[] columns, boolean is03Format) throws Exception {
List<T> result = new ArrayList<>();
Workbook workbook = null;
if (is03Format) {
workbook = new HSSFWorkbook(in);
} else {
workbook = new XSSFWorkbook(in);
}
// 取得sheet的数量
int sheetSize = workbook.getNumberOfSheets();
for (int i = 0; i < sheetSize; i++) {
Sheet sheet = workbook.getSheetAt(i);
// 取得sheet的总行数
int rows = sheet.getPhysicalNumberOfRows();
int cellNum = 0;
for (int j = 0; j < rows; j++) {
T rowData = clazz.newInstance();
if (j == 0) {
// 以第0行的表头为准
cellNum = sheet.getRow(0).getPhysicalNumberOfCells();
if (cellNum != columns.length) {
throw new ServiceException("表头长度和实际配置columns长度不一致");
}
}
Row row = sheet.getRow(j);
for (int k = 0; k < cellNum; k++) {
if (row == null) {
continue;
}
Cell cell = row.getCell(k);
Object cellValue = null;
if (null != cell) {
switch(cell.getCellTypeEnum()) {
case STRING:
cellValue = cell.getStringCellValue();
break;
case NUMERIC:
cellValue = cell.getNumericCellValue();
// 时间
if (HSSFDateUtil.isCellDateFormatted(cell)) {
cellValue = cell.getDateCellValue();
}
break;
case BOOLEAN:
cellValue = cell.getBooleanCellValue();
break;
case FORMULA:
cellValue = cell.getCellFormula();
break;
case BLANK:
break;
default:
cellValue = null;
break;
}
}
Field field = ReflectionUtils.findField(clazz, columns[k]);
if (null == field) {
throw new ServiceException(columns[k] + " 配置错误");
}
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, rowData, cellValue);
}
result.add(rowData);
}
}
workbook.close();
return result;
}
16
View Source File : HateoasObjenesisCacheDisabler.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private void removeObjenesisCache(Clreplaced<?> dummyInvocationUtils) {
try {
Field objenesisField = ReflectionUtils.findField(dummyInvocationUtils, "OBJENESIS");
if (objenesisField != null) {
ReflectionUtils.makeAccessible(objenesisField);
Object objenesis = ReflectionUtils.getField(objenesisField, null);
Field cacheField = ReflectionUtils.findField(objenesis.getClreplaced(), "cache");
ReflectionUtils.makeAccessible(cacheField);
ReflectionUtils.setField(cacheField, objenesis, null);
}
} catch (Exception ex) {
logger.warn("Failed to disable Spring HATEOAS's Objenesis cache. ClreplacedCastExceptions may occur", ex);
}
}
16
View Source File : RaftAnnotationBeanPostProcessor.java
License : Apache License 2.0
Project Creator : sofastack
License : Apache License 2.0
Project Creator : sofastack
private void processRaftReference(Object bean) {
final Clreplaced<?> beanClreplaced = bean.getClreplaced();
ReflectionUtils.doWithFields(beanClreplaced, field -> {
RaftReference referenceAnnotation = field.getAnnotation(RaftReference.clreplaced);
if (referenceAnnotation == null) {
return;
}
Clreplaced<?> interfaceType = referenceAnnotation.interfaceType();
if (interfaceType.equals(void.clreplaced)) {
interfaceType = field.getType();
}
String serviceId = getServiceId(interfaceType, referenceAnnotation.uniqueId());
Object proxy = getProxy(interfaceType, serviceId);
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, bean, proxy);
}, field -> !Modifier.isStatic(field.getModifiers()) && field.isAnnotationPresent(RaftReference.clreplaced));
}
16
View Source File : ConsultaController.java
License : MIT License
Project Creator : renatoredes
License : MIT License
Project Creator : renatoredes
private void merge(Map<String, Object> dadosOrigem, Consulta consultaDestino) {
ObjectMapper objectMapper = new ObjectMapper();
Consulta consultaOrigem = objectMapper.convertValue(dadosOrigem, Consulta.clreplaced);
dadosOrigem.forEach((nomePropriedade, valorPropriedade) -> {
Field field = ReflectionUtils.findField(Consulta.clreplaced, nomePropriedade);
field.setAccessible(true);
Object novoValor = ReflectionUtils.getField(field, consultaOrigem);
ReflectionUtils.setField(field, consultaDestino, novoValor);
});
}
16
View Source File : AbstractTest.java
License : Apache License 2.0
Project Creator : OpenWiseSolutions
License : Apache License 2.0
Project Creator : OpenWiseSolutions
/**
* Sets value of private field.
*
* @param target the target object
* @param name the field name
* @param value the value for setting to the field
*/
public static void setPrivateField(Object target, String name, Object value) {
Field countField = ReflectionUtils.findField(target.getClreplaced(), name);
ReflectionUtils.makeAccessible(countField);
ReflectionUtils.setField(countField, target, value);
}
16
View Source File : ValidatorUtil.java
License : Apache License 2.0
Project Creator : landy8530
License : Apache License 2.0
Project Creator : landy8530
public static void setNullIfInvalid(CustomerRequestDetail detail, String columnName) {
Field dataField = ReflectionUtils.findField(CustomerRequestDetail.clreplaced, columnName);
ReflectionUtils.makeAccessible(dataField);
ReflectionUtils.setField(dataField, detail, null);
}
16
View Source File : DefaultFirebaseRealtimeDatabaseRepository.java
License : MIT License
Project Creator : fabiomaffioletti
License : MIT License
Project Creator : fabiomaffioletti
@Override
public T set(T doreplacedent, Object... uriVariables) {
ReflectionUtils.makeAccessible(doreplacedentId);
ID id = (ID) ReflectionUtils.getField(doreplacedentId, doreplacedent);
replacedert id != null : "When using set an id value must be specified";
HttpEnreplacedy httpEnreplacedy = HttpEnreplacedyBuilder.create(firebaseObjectMapper, firebaseApplicationService).doreplacedent(doreplacedent).build();
T response = restTemplate.exchange(getDoreplacedentPath(id), HttpMethod.PUT, httpEnreplacedy, doreplacedentClreplaced, uriVariables).getBody();
ReflectionUtils.setField(doreplacedentId, response, id);
return response;
}
16
View Source File : DefaultFirebaseRealtimeDatabaseRepository.java
License : MIT License
Project Creator : fabiomaffioletti
License : MIT License
Project Creator : fabiomaffioletti
private List<T> readAsList(String responseString) throws IOException {
List<T> result = Lists.newArrayList();
FirebaseMapFindResponse<ID, T> response = firebaseObjectMapper.readValue(responseString, new FirebaseObjectListTypeReference(firebaseMapFindResponseParameterizedTypeReference));
if (response != null) {
response.forEach((key, value) -> {
ReflectionUtils.makeAccessible(doreplacedentId);
ReflectionUtils.setField(doreplacedentId, value, key);
result.add(value);
});
}
return result;
}
16
View Source File : ConfigurableBundleCreatorTestsTest.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
public void testDefaultJarSettings() throws Exception {
Properties defaultSettings = bundleCreator.getSettings();
Field field = ReflectionUtils.findField(AbstractConfigurableBundleCreatorTests.clreplaced, "jarSettings", Properties.clreplaced);
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, null, defaultSettings);
replacedertNotNull(defaultSettings);
replacedertNotNull(bundleCreator.getRootPath());
replacedertNotNull(bundleCreator.getBundleContentPattern());
replacedertNotNull(bundleCreator.getManifestLocation());
}
16
View Source File : ReflectionSupport.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
public static void setId(Object value, URI uri) {
Field idField = getIdField(value.getClreplaced());
idField.setAccessible(true);
ReflectionUtils.setField(idField, value, uri);
}
16
View Source File : ConfigCenterPropertyPlaceholderConfigurerTest.java
License : Apache License 2.0
Project Creator : baidu
License : Apache License 2.0
Project Creator : baidu
public static void setFieldValue(Object target, String fieldName, Object value) {
if (target == null || !StringUtils.hasText(fieldName)) {
return;
}
Clreplaced<?> targetClreplaced = target.getClreplaced();
Field field = ReflectionUtils.findField(targetClreplaced, fieldName);
if (field == null) {
return;
}
boolean oldAccessible = field.isAccessible();
field.setAccessible(true);
ReflectionUtils.setField(field, target, value);
field.setAccessible(oldAccessible);
}
15
View Source File : ElasticsearchIndexServiceUnitTest.java
License : Apache License 2.0
Project Creator : xm-online
License : Apache License 2.0
Project Creator : xm-online
@SneakyThrows
private static <T> T createObject(Clreplaced<T> enreplacedyClreplaced) {
T instance = enreplacedyClreplaced.newInstance();
Field id = ReflectionUtils.findField(enreplacedyClreplaced, "id");
id.setAccessible(true);
ReflectionUtils.setField(ReflectionUtils.findField(enreplacedyClreplaced, "id"), instance, 777L);
return instance;
}
15
View Source File : DelegatingOAuth2AccessTokenResponseClient.java
License : Apache License 2.0
Project Creator : penggle
License : Apache License 2.0
Project Creator : penggle
protected void handleTokenResponse(OAuth2AccessTokenResponse tokenResponse) {
OAuth2AccessToken oldAccessToken = tokenResponse.getAccessToken();
if (oldAccessToken != null) {
OAuth2AccessToken newAccessToken = new OAuth2AccessToken(oldAccessToken.getTokenType(), oldAccessToken.getTokenValue(), adjustInstant(oldAccessToken.getIssuedAt()), adjustInstant(oldAccessToken.getExpiresAt()), oldAccessToken.getScopes());
ReflectionUtils.setField(accessTokenField, tokenResponse, newAccessToken);
}
OAuth2RefreshToken oldRefreshToken = tokenResponse.getRefreshToken();
if (oldRefreshToken != null) {
OAuth2RefreshToken newRefreshToken = new OAuth2RefreshToken(oldRefreshToken.getTokenValue(), adjustInstant(oldRefreshToken.getIssuedAt()));
ReflectionUtils.setField(refreshTokenField, tokenResponse, newRefreshToken);
}
}
15
View Source File : InjectRandomIntAnnotationBeanPostProcessor.java
License : Apache License 2.0
Project Creator : linnykoleh
License : Apache License 2.0
Project Creator : linnykoleh
/**
* Вызывается ДО init метода
*/
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
final Field[] fields = bean.getClreplaced().getDeclaredFields();
for (Field field : fields) {
final InjectRandomInt annotation = field.getAnnotation(InjectRandomInt.clreplaced);
if (annotation != null) {
final int min = annotation.min();
final int max = annotation.max();
Random random = new Random();
int i = random.nextInt(max - min);
field.setAccessible(true);
ReflectionUtils.setField(field, bean, i);
}
}
return bean;
}
15
View Source File : PersistentPropertyConvertingCallback.java
License : Apache License 2.0
Project Creator : kaiso
License : Apache License 2.0
Project Creator : kaiso
private void checkIdentifier(Object obj) {
try {
ObjectIdReaderCallback objectIdReaderCallback = new ObjectIdReaderCallback(obj);
ReflectionUtils.doWithFields(obj.getClreplaced(), objectIdReaderCallback);
Field idField = objectIdReaderCallback.getIdField();
if (idField == null) {
throw new RelMongoConfigurationException("the Id field of clreplaced [" + obj.getClreplaced() + "] must be annotated by @Id (org.springframework.data.annotation.Id)");
}
if (idField.get(obj) == null) {
ReflectionUtils.setField(idField, obj, generateId(idField));
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RelMongoProcessingException(e);
}
}
15
View Source File : DefaultFirebaseRealtimeDatabaseRepository.java
License : MIT License
Project Creator : fabiomaffioletti
License : MIT License
Project Creator : fabiomaffioletti
@Override
public T get(ID id, Object... uriVariables) throws FirebaseRepositoryException {
ReflectionUtils.makeAccessible(doreplacedentId);
HttpEnreplacedy httpEnreplacedy = HttpEnreplacedyBuilder.create(firebaseObjectMapper, firebaseApplicationService).build();
T response = restTemplate.exchange(getDoreplacedentPath(id), HttpMethod.GET, httpEnreplacedy, doreplacedentClreplaced, uriVariables).getBody();
if (response == null) {
throw new HttpClientErrorException(HttpStatus.NOT_FOUND);
} else {
ReflectionUtils.setField(doreplacedentId, response, id);
return response;
}
}
15
View Source File : DefaultFirebaseRealtimeDatabaseRepository.java
License : MIT License
Project Creator : fabiomaffioletti
License : MIT License
Project Creator : fabiomaffioletti
@Override
public T push(T doreplacedent, Object... uriVariables) {
ReflectionUtils.makeAccessible(doreplacedentId);
HttpEnreplacedy httpEnreplacedy = HttpEnreplacedyBuilder.create(firebaseObjectMapper, firebaseApplicationService).doreplacedent(doreplacedent).build();
FirebasePushResponse response = restTemplate.exchange(getDoreplacedentPath(), HttpMethod.POST, httpEnreplacedy, FirebasePushResponse.clreplaced, uriVariables).getBody();
replacedert response != null : String.format("Response is null for push doreplacedent of clreplaced %s", doreplacedentClreplaced.getSimpleName());
ReflectionUtils.setField(doreplacedentId, doreplacedent, response.getName());
return doreplacedent;
}
15
View Source File : DefaultFirebaseRealtimeDatabaseRepository.java
License : MIT License
Project Creator : fabiomaffioletti
License : MIT License
Project Creator : fabiomaffioletti
@Override
public T update(T doreplacedent, Object... uriVariables) {
ReflectionUtils.makeAccessible(doreplacedentId);
ID id = (ID) ReflectionUtils.getField(doreplacedentId, doreplacedent);
replacedert id != null : "When using update an id value must be specified";
HttpEnreplacedy httpEnreplacedy = HttpEnreplacedyBuilder.create(firebaseObjectMapper, firebaseApplicationService).header("X-HTTP-Method-Override", HttpMethod.PATCH.name()).doreplacedent(doreplacedent).build();
T response = restTemplate.exchange(getDoreplacedentPath(id), HttpMethod.PUT, httpEnreplacedy, doreplacedentClreplaced, uriVariables).getBody();
ReflectionUtils.setField(doreplacedentId, response, id);
return response;
}
14
View Source File : AssetLineageClientTest.java
License : Apache License 2.0
Project Creator : odpi
License : Apache License 2.0
Project Creator : odpi
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
replacedetLineage = new replacedetLineage(SERVER_NAME, SERVER_URL);
Field connectorField = ReflectionUtils.findField(replacedetLineage.clreplaced, "clientConnector");
if (connectorField != null) {
connectorField.setAccessible(true);
ReflectionUtils.setField(connectorField, replacedetLineage, connector);
connectorField.setAccessible(false);
}
}
14
View Source File : AssetCatalogRelationshipServiceTest.java
License : Apache License 2.0
Project Creator : odpi
License : Apache License 2.0
Project Creator : odpi
@Before
public void before() {
MockitoAnnotations.initMocks(this);
Field instanceHandlerField = ReflectionUtils.findField(replacedetCatalogRelationshipRESTService.clreplaced, "instanceHandler");
instanceHandlerField.setAccessible(true);
ReflectionUtils.setField(instanceHandlerField, replacedetCatalogRelationshipService, instanceHandler);
instanceHandlerField.setAccessible(false);
Field restExceptionHandlerField = ReflectionUtils.findField(replacedetCatalogRelationshipRESTService.clreplaced, "restExceptionHandler");
restExceptionHandlerField.setAccessible(true);
ReflectionUtils.setField(restExceptionHandlerField, replacedetCatalogRelationshipService, restExceptionHandler);
restExceptionHandlerField.setAccessible(false);
response = mockRelationshipResponse();
}
14
View Source File : PersistentPropertyConvertingCallback.java
License : Apache License 2.0
Project Creator : kaiso
License : Apache License 2.0
Project Creator : kaiso
public void doWith(Field field) throws IllegalAccessException {
ReflectionUtils.makeAccessible(field);
if (AnnotationsUtils.isMappedBy(field)) {
ReflectionUtils.setField(field, source, null);
return;
}
MappedByProcessor.processChild(source, null, field, ReflectionsUtil.getGenericType(field));
if (field.isAnnotationPresent(OneToMany.clreplaced)) {
fillIdentifiers(field, field.getAnnotation(OneToMany.clreplaced).cascade());
} else if (field.isAnnotationPresent(OneToOne.clreplaced)) {
fillIdentifiers(field, field.getAnnotation(OneToOne.clreplaced).cascade());
}
}
14
View Source File : DefaultFirebaseRealtimeDatabaseRepository.java
License : MIT License
Project Creator : fabiomaffioletti
License : MIT License
Project Creator : fabiomaffioletti
private List<T> readAsArray(String responseString) throws IOException {
List<T> collect = firebaseObjectMapper.readValue(responseString, new FirebaseObjectListTypeReference(firebaseArrayFindResponseParameterizedTypeReference));
LongStream.range(0, collect.size()).forEach(index -> {
if (collect.get((int) index) != null) {
ReflectionUtils.makeAccessible(doreplacedentId);
// for now only Integer and Long are supported
if (doreplacedentIdClreplaced.equals(Integer.clreplaced)) {
ReflectionUtils.setField(doreplacedentId, collect.get((int) index), (int) index);
} else {
ReflectionUtils.setField(doreplacedentId, collect.get((int) index), index);
}
}
});
return collect;
}
14
View Source File : RpcReferenceProcessor.java
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
private void handleReferenceField(Object obj, Field field, RpcReference reference) {
String microserviceName = reference.microserviceName();
microserviceName = resolver.resolveStringValue(microserviceName);
PojoReferenceMeta pojoReference = new PojoReferenceMeta();
pojoReference.setMicroserviceName(microserviceName);
pojoReference.setSchemaId(reference.schemaId());
pojoReference.setConsumerIntf(field.getType());
pojoReference.afterPropertiesSet();
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, obj, pojoReference.getProxy());
}
13
View Source File : MockitoTestExecutionListener.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private void reinjectFields(final TestContext testContext) {
postProcessFields(testContext, (mockitoField, postProcessor) -> {
ReflectionUtils.makeAccessible(mockitoField.field);
ReflectionUtils.setField(mockitoField.field, testContext.getTestInstance(), null);
postProcessor.inject(mockitoField.field, mockitoField.target, mockitoField.definition);
});
}
13
View Source File : ReflectionTestUtils.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Set the {@linkplain Field field} with the given {@code name}/{@code type}
* on the provided {@code targetObject}/{@code targetClreplaced} to the supplied
* {@code value}.
* <p>If the supplied {@code targetObject} is a <em>proxy</em>, it will
* be {@linkplain AopTestUtils#getUltimateTargetObject unwrapped} allowing
* the field to be set on the ultimate target of the proxy.
* <p>This method traverses the clreplaced hierarchy in search of the desired
* field. In addition, an attempt will be made to make non-{@code public}
* fields <em>accessible</em>, thus allowing one to set {@code protected},
* {@code private}, and <em>package-private</em> fields.
* @param targetObject the target object on which to set the field; may be
* {@code null} if the field is static
* @param targetClreplaced the target clreplaced on which to set the field; may
* be {@code null} if the field is an instance field
* @param name the name of the field to set; may be {@code null} if
* {@code type} is specified
* @param value the value to set
* @param type the type of the field to set; may be {@code null} if
* {@code name} is specified
* @since 4.2
* @see ReflectionUtils#findField(Clreplaced, String, Clreplaced)
* @see ReflectionUtils#makeAccessible(Field)
* @see ReflectionUtils#setField(Field, Object, Object)
* @see AopTestUtils#getUltimateTargetObject(Object)
*/
public static void setField(@Nullable Object targetObject, @Nullable Clreplaced<?> targetClreplaced, @Nullable String name, @Nullable Object value, @Nullable Clreplaced<?> type) {
replacedert.isTrue(targetObject != null || targetClreplaced != null, "Either targetObject or targetClreplaced for the field must be specified");
if (targetObject != null && springAopPresent) {
targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
}
if (targetClreplaced == null) {
targetClreplaced = targetObject.getClreplaced();
}
Field field = ReflectionUtils.findField(targetClreplaced, name, type);
if (field == null) {
throw new IllegalArgumentException(String.format("Could not find field '%s' of type [%s] on %s or target clreplaced [%s]", name, type, safeToString(targetObject), targetClreplaced));
}
if (logger.isDebugEnabled()) {
logger.debug(String.format("Setting field '%s' of type [%s] on %s or target clreplaced [%s] to value [%s]", name, type, safeToString(targetObject), targetClreplaced, value));
}
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, targetObject, value);
}
13
View Source File : VenusSpringMvcContract.java
License : Apache License 2.0
Project Creator : SpringCloud
License : Apache License 2.0
Project Creator : SpringCloud
@Override
public MethodMetadata parseAndValidateMetadata(Clreplaced<?> targetType, Method method) {
this.processedMethods.put(Feign.configKey(targetType, method), method);
MethodMetadata md = super.parseAndValidateMetadata(targetType, method);
RequestMapping clreplacedAnnotation = findMergedAnnotation(targetType, RequestMapping.clreplaced);
if (clreplacedAnnotation != null) {
// produces - use from clreplaced annotation only if method has not specified this
if (!md.template().headers().containsKey(ACCEPT)) {
parseProduces(md, method, clreplacedAnnotation);
}
// consumes -- use from clreplaced annotation only if method has not specified this
if (!md.template().headers().containsKey(CONTENT_TYPE)) {
parseConsumes(md, method, clreplacedAnnotation);
}
// headers -- clreplaced annotation is inherited to methods, always write these if
// present
parseHeaders(md, method, clreplacedAnnotation);
}
// 扩展SpringMvcContract
String rawUrl = md.template().url();
String url = rawUrl;
List<String> pathVariableList = new ArrayList<>();
// 处理path value含有正则问题
Matcher matcher = pattern.matcher(url);
while (matcher.find()) {
String pathVariable = matcher.group();
int endIndex = pathVariable.indexOf(":");
if (endIndex != -1) {
String rawPathVariable = pathVariable.substring(1, endIndex);
pathVariableList.add(rawPathVariable);
url = url.replace(pathVariable, "{" + rawPathVariable + "}");
} else {
String rawPathVariable = pathVariable.substring(1, pathVariable.length() - 1);
pathVariableList.add(rawPathVariable);
}
}
// 处理path value不存在方法参数问题
for (String pathVariable : pathVariableList) {
if (!hasPathVariable(md, pathVariable)) {
url = url.replace("{" + pathVariable + "}", defaultValue(method, pathVariable));
ReflectionUtils.setField(requestTemplateUrl, md.template(), new StringBuilder(url));
}
}
LOGGER.info("{} > {}", rawUrl, url);
return md;
}
13
View Source File : OpenFeignSpringMvcContract.java
License : Apache License 2.0
Project Creator : spring-avengers
License : Apache License 2.0
Project Creator : spring-avengers
@Override
public MethodMetadata parseAndValidateMetadata(Clreplaced<?> targetType, Method method) {
this.processedMethods.put(Feign.configKey(targetType, method), method);
MethodMetadata md = super.parseAndValidateMetadata(targetType, method);
RequestMapping clreplacedAnnotation = findMergedAnnotation(targetType, RequestMapping.clreplaced);
if (clreplacedAnnotation != null) {
if (!md.template().headers().containsKey(ACCEPT)) {
parseProduces(md, method, clreplacedAnnotation);
}
if (!md.template().headers().containsKey(CONTENT_TYPE)) {
parseConsumes(md, method, clreplacedAnnotation);
}
parseHeaders(md, method, clreplacedAnnotation);
}
String rawUrl = md.template().url();
String url = rawUrl;
List<String> pathVariableList = new ArrayList<>();
Matcher matcher = pattern.matcher(url);
while (matcher.find()) {
String pathVariable = matcher.group();
int endIndex = pathVariable.indexOf(":");
if (endIndex != -1) {
String rawPathVariable = pathVariable.substring(1, endIndex);
pathVariableList.add(rawPathVariable);
url = url.replace(pathVariable, "{" + rawPathVariable + "}");
} else {
String rawPathVariable = pathVariable.substring(1, pathVariable.length() - 1);
pathVariableList.add(rawPathVariable);
}
}
for (String pathVariable : pathVariableList) {
if (!hasPathVariable(md, pathVariable)) {
url = url.replace("{" + pathVariable + "}", defaultValue(method, pathVariable));
ReflectionUtils.setField(requestTemplateUrl, md.template(), new StringBuilder(url));
}
}
String apiVersion = ApiVersionUtils.getFirstValue(targetType, method);
if (!StringUtils.isEmpty(apiVersion)) {
md.template().insert(0, "/" + apiVersion);
}
LOGGER.info("{} > {}", rawUrl, url);
md.template().header(CLreplaced_HEADER, targetType.getSimpleName()).header(METHOD_HEADER, method.getName());
return md;
}
13
View Source File : LogBackConfiguration.java
License : Apache License 2.0
Project Creator : spring-avengers
License : Apache License 2.0
Project Creator : spring-avengers
private void setLayout(LoggerContext loggerContext, OutputStreamAppender outputStreamAppender) {
Encoder<?> encoder = outputStreamAppender.getEncoder();
if (encoder instanceof LayoutWrappingEncoder) {
TraceIdPatternLogbackLayout traceIdLayOut = new TraceIdPatternLogbackLayout();
traceIdLayOut.setContext(loggerContext);
traceIdLayOut.setPattern(getLogBackPattern());
traceIdLayOut.start();
Field field = ReflectionUtils.findField(encoder.getClreplaced(), "layout");
field.setAccessible(true);
ReflectionUtils.setField(field, encoder, traceIdLayOut);
}
}
See More Examples