How to use @JsonIdentityInfo with circular references?

I am trying to use the @JsonIdentityInfo from Jackson 2 as described here. For testing purposes I created the following two classes: public class A { private B b; // constructor(s) and getter/setter omitted } public class B { private A a; // see above } Of course, the naive approach failes: @Test public void … Read more

Method reference in Java 8

public class Car { private int maxSpeed; public Car(int maxSpeed) { this.maxSpeed = maxSpeed; } public int getMaxSpeed() { return maxSpeed; } } We can sort a list of cars by, Car carX = new Car(155); Car carY = new Car(140); List<Car> cars = new ArrayList<>(); cars.add(carX); cars.add(carY); cars.sort(Comparator.comparing(Car::getMaxSpeed)); If we see the signature of … Read more

Error creating bean with name ‘requestMappingHandlerAdapter’

Am creating a simple REST service using Springframework with Tomcat. The response should have to be in json like {“id”:”101″,”name”:”Ram”} .When ever I run, am getting the following error org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘requestMappingHandlerAdapter’ defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerAdapter()] threw exception; … Read more

Understanding Spring Boot @Autowired

I don’t understand how spring boot’s annotation @Autowired correctly works. Here is a simple example: @SpringBootApplication public class App { @Autowired public Starter starter; public static void main(String[] args) { SpringApplication.run(App.class, args); } public App() { System.out.println(“init App”); //starter.init(); } } — @Repository public class Starter { public Starter() {System.out.println(“init Starter”);} public void init() { … Read more

Spring-boot with spring-mybatis – how to force it to logging all SQL queries

I have a simple spring-boot-mybatis app (keep in mind, please). Mybatis is logging SQL queries only in case of failure (on excepions). Tell me please, how to force it to log all SQL query to console ? At this moment I am using slf4j logger (automatically configured by spring-boot). I find this link: http://www.mybatis.org/mybatis-3/logging.html however … Read more

Android Studio: Failed to create MD5 HashFile

I am creating a simple android application… I ran into some kind of trouble when I updated gradle when I launched Android Studio and it prompted me too. Upon the update completing I receive the following error: Error:Execution failed for task ‘:app:compileDebugJavaWithJavac’. Failed to create MD5 hash for file ‘/Users/damenTomassi/AndroidStudioProjects/AstraeaDemo/app/src/main/res/libs/gson-2.3.1.jar’. I used to have the … Read more

Spring: Different exception handler for RestController and Controller

In Spring you can set up “global” exception handler via @ControllerAdvice and @ExceptionHandler annotation. I’m trying to utilize this mechanism to have two global exception handlers: RestControllerExceptionHandler – which should return error responses as json for any controller annotated with @RestController ControllerExceptionHandler – which should print error message to the screen for any other controller … Read more

Initialize Map instance from Map entries

Say I have some map entries like so: var a = Map.entry(“a”, new Object()); var b = Map.entry(“b”, new Object()); var c = Map.entry(“c”, new Object()); var m = Map.of(a,b,c); // error here I get this error: Cannot resolve method ‘of(java.util.Map.Entry, java.util.Map.Entry, java.util.Map.Entry)’ I just want to make a new Map from entries in a … Read more

Java 11: Implementation of JAXB-API has not been found on module path or classpath

I have a little project which does throw an exception when i let it run. The problem is here (TestObject.java): final JAXBContext jaxbContext = JAXBContext.newInstance(…); I really do not understand why this throws the exception. I also created a test which works like a charm (TestTest.java). Please forgive me the names, but this is just … Read more

Java: manually-unrolled loop is still faster than the original loop. Why?

Consider the following two snippets of code on an array of length 2: boolean isOK(int i) { for (int j = 0; j < filters.length; ++j) { if (!filters[j].isOK(i)) { return false; } } return true; } and boolean isOK(int i) { return filters[0].isOK(i) && filters[1].isOK(i); } I would assume that the performance of these … Read more