java
Don’t return property when it’s an empty list with jackson
You can use @JsonInclude(JsonInclude.Include.NON_EMPTY) annotation on your class or filed. import com.fasterxml.jackson.annotation.JsonInclude; @JsonInclude(JsonInclude.Include.NON_EMPTY) class Person { String name; List<Event> events; //….getter, setter }
Understanding logic in CaseInsensitiveComparator
From Unicode Technical Standard: In addition, because of the vagaries of natural language, there are situations where two different Unicode characters have the same uppercase or lowercase So, it’s not enough to compare only uppercase of two characters, because they may have different uppercase and same lowercase Simple brute force check gives some results. Check … Read more
Can’t install JDK 9 because “Another Java installation is in progress”
On Windows, Java prevents starting the Installer twice by creating (two) lock files. If those files exist, Java Installer show the Message: “Another Java installation is in progress (…)”. If Java Installer crashes, or Windows crashes during Java Installation, the installer cannot delete the lock files when finalizing. Solution: Deleting the lock files, unlocks the … Read more
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server [duplicate]
The problem is the compatibility of older versions of MySQL Connector/J with MySQL 8. You need to upgrade to either MySQL Connector/J 5.1.46 or – better – 8.0.11 (or a higher version).
How to apply spring boot filter based on URL pattern?
There is another option if you are able to extend OncePerRequestFilter. For example: public class SomeFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { // your filter logic …. } @Override protected boolean shouldNotFilter(HttpServletRequest request) { String path = request.getServletPath(); return !path.startsWith(“/api/secure/”); } }
Spring Boot validation message is not being resolved
It looks like you are missing LocalValidatorFactoryBean definition in your application configuration. Below you can find an example of Application class that defines two beans: LocalValidatorFactoryBean and MessageSource that uses messages.properties file. import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.support.ReloadableResourceBundleMessageSource; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; @SpringBootApplication public class Application { @Bean public MessageSource messageSource() { ReloadableResourceBundleMessageSource … Read more
How do I display a message if a jsf datatable is empty?
Make use of the rendered attribute. It accepts a boolean expression. You can evaluate the datatable’s value inside the expression with help of the EL’s empty keyword. If it returns false, the whole component (and its children) won’t be rendered. <h:outputText value=”Table is empty!” rendered=”#{empty bean.list}” /> <h:dataTable value=”#{bean.list}” rendered=”#{not empty bean.list}”> … </h:dataTable> For … Read more
velocity: do something except in last loop iteration
You can use a test if you are in last iteration:: #foreach( $item in $list ) $item.text #if( $foreach.hasNext ), #end #end