I am using a common RestTemplate to submit a request to Remote server. Where I am first making a login request, fetching the webToken and then making subsequent request using that token.
In this common RestTemplate, I am logging the request and response. But I want to avert logging the username and password in logging. Following is the example which I am trying to do.
package reflection;
public class TypeCheck {
public static void main(String[] args) {
Object animal = new Animal("Elephant");
classType(animal.getClass());
//Passing Class Type
// Output - Unmatched class reflection.Animal
}
private static void classType(Object type) {
if(type instanceof Animal) {
System.out.println("Matched "+ type);
}
System.out.println("Unmatched " + type);
}
}
class Animal {
String name;
public Animal(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Now, I want to extract the Class Type (i.e. reflection.Animal) from type parameter. I tried for type.getClass().getSimpleName() and some other methods but not getting better way to do it.
P.S. - Currently I am trying one clumsy way (as I think) to fetch this. But don't know if this is correct or we have some better way to achieve this.
if(type.toString().contains("Animal")) {
System.out.println("Matched "+ type);
}
Thanks in advance.
animalinstead ofanimal.getClass()to theclassTypemethod.