I want to do something like this with subtypes. I have 3 different types of objects: value can either be a string or an object. The corresponding Java classes are I don’t mind having a discriminator inside Obj1 and Obj2, but there is no place for one when the value is just a string. Is there a way that …
Tag: java
How to test a service or do it right mock? Java11, Spock Framework
Colleagues, I welcome you all! Tell me how to decide, or how to act. (Java11, SpringBoot, testing – Spock Framework) I need to write a test that will test a class method, the whole problem is that the method of the class under test calls another service through inheritance, which is not declared in the …
Apache HttpClient: first call very slow, following calls very fast
I am using Apache HttpClient 4.5.13 since some years and I have no problems until today. In a Springboot app when it call a specific server, the first call (or the first call after some inactivity) required about 8 seconds (!!!) then all the following calls (to the same server) are very fast (less than a seco…
Java ternary operator on simple binary search problem
How can I refactor this code to NOT include “int ans =” I’d like to keep the ternary operator. Since int ans is not actually the answer it makes no sense to keep it this way. What would be the correct way to use the ternary operator to change the left / right values? Answer The conditional o…
strange reuslt when adding integers in JAVA [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed las…
What should we do for nested objects in Room? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question If there is a structure like my JSON structure below, how should we create Entity Classes? The…
Relationship mapping in Hibernate Java – save owning side entity
I have 2 tables User Url I’m trying to create a relationship between said 2 tables. A user can have many urls, but a url can belong to only one user. This sounds to me like a OneToMany relationship. My User Entity is as follows(some code was removed as to not make it too long): My Url Entity is as
Throwing custom errors as Json when a parameter is invalid
I am working on an API and need to throw and exception that looks like this if the sort by parameter is not one of my predetermined values, i have a few parameters to do this for here is what my controller looks like ive remove the url but it works for sorting the incoming data but i need to
Trying to reverse my stream in ascending order – Java 8
This idea behind this code is that it reads the data from three .csv files w/ keys organized by year, and retrieves the sum of the data by year, as well as the minimum and maximum number for each year. The problem is, when print it returns the yearly results in descending order. I need help figuring out a way
Module not found: javafx.web
I wanted to create a WebView with Javafx, and I added requires javafx.web; to my module-info.jar, but IntelliJ say: “Module not found: javafx.web”. works without any problem. What can I do? Answer Have you also added a dependency to javafx-web in Maven/Gradle or added the corresponding jar file to…