Last active
February 5, 2019 00:01
-
-
Save dvelez-jimenez/d89873388a371fcbfc5ad2081c64056d to your computer and use it in GitHub Desktop.
Magia negra de injeccion de parametros usando reflection by Airon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Field; | |
import java.util.map; | |
public class ObjectUtil { | |
public static void injectFromMap(Object t1, Map<String, String> props) throws IllegalArgumentException, IllegalAccessException{ | |
Class<? extends Object> c = t1.getClass(); | |
Field[] fields = t1.getClass().getDeclaredFields(); | |
for(Field field: fields){ | |
String fullName = c.getName() + "." + field.getName(); | |
if(props.contains(fullName)){ | |
boolean oldAccesible = f.isAccesible(); | |
field.setAccesible(true); | |
field.set(t1, props.get(fullName)); | |
f.setAccesible(oldAccesible); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Map<String, String> parameters; | |
ObjectUtil.injectFormMap(this, parameters); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Magia negra de injeccion de parametros By Airon