Scanning Java annotations at runtime

Use org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider API A component provider that scans the classpath from a base package. It then applies exclude and include filters to the resulting classes to find candidates. ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(<DO_YOU_WANT_TO_USE_DEFALT_FILTER>); scanner.addIncludeFilter(new AnnotationTypeFilter(<TYPE_YOUR_ANNOTATION_HERE>.class)); for (BeanDefinition bd : scanner.findCandidateComponents(<TYPE_YOUR_BASE_PACKAGE_HERE>)) System.out.println(bd.getBeanClassName());

How do I assert my exception message with JUnit Test annotation?

You could use the @Rule annotation with ExpectedException, like this: @Rule public ExpectedException expectedEx = ExpectedException.none(); @Test public void shouldThrowRuntimeExceptionWhenEmployeeIDisNull() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage(“Employee ID is null”); // do something that should throw the exception… System.out.println(“=======Starting Exception process=======”); throw new NullPointerException(“Employee ID is null”); } Note that the example in the ExpectedException docs is … Read more

@Nullable annotation usage

It makes it clear that the method accepts null values, and that if you override the method, you should also accept null values. It also serves as a hint for code analyzers like FindBugs. For example, if such a method dereferences its argument without checking for null first, FindBugs will emit a warning.

Only using @JsonIgnore during serialization, but not deserialization

Exactly how to do this depends on the version of Jackson that you’re using. This changed around version 1.9, before that, you could do this by adding @JsonIgnore to the getter. Which you’ve tried: Add @JsonIgnore on the getter method only Do this, and also add a specific @JsonProperty annotation for your JSON “password” field … Read more

JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object

So, finally I realized what the problem is. It is not a Jackson configuration issue as I doubted. Actually the problem was in ApplesDO Class: public class ApplesDO { private String apple; public String getApple() { return apple; } public void setApple(String apple) { this.apple = apple; } public ApplesDO(CustomType custom) { //constructor Code } … Read more

Should we @Override an interface’s method implementation?

You should use @Override whenever possible. It prevents simple mistakes from being made. Example: class C { @Override public boolean equals(SomeClass obj){ // code … } } This doesn’t compile because it doesn’t properly override public boolean equals(Object obj). The same will go for methods that implement an interface (1.6 and above only) or override … Read more