Skip to content

Tag: java

Hashmap using lists as a buffer

I need to create a hashmap that can store multiple values for one key, I know multimaps could do this but I also need to keep those value lists to a specific length. I need a each key to store a list of n values with those being the latest n values, i.e if i reached length n and I

Java Spring omits fields when making a JSON

I have an object that looks more or less like this, and I use it as a GET response for my API. scores and values are both database entities. I wanted to add a String to the response with some additional information. What happens is that the objects are properly turned into a JSON and they show up in the

“grade” cannot be resolved to a variable

I have this exercise and the question is how can I solve the error “grade” cannot be resolved to a variable, without declare it in the class teacher. I suppose is the only error in my code. It is evident for me WHY then in my output only the grade variable is not assigned, but I don’t know H…

@SubclassMapping order

First time using MapStruct (1.5.0.Beta2) Say I have the following class hierarchy: C extends B extends A and Cdto extends Bdto extends Adto. And the following mapper: When I map a list of C objects I actually get a list of Bdtos. If however I change the ordering to: I get a list of Cdtos as expected. Is this …

How to use ${akka.kafka.consumer}?

I’m attempting to use the default Kafka config settings but I’m unsure how ${akka.kafka.consumer} is set. Reading https://doc.akka.io/docs/alpakka-kafka/current/consumer.html#config-inheritance Ive defined the following : In application.conf I define : But receive error when I startup the Akka Clu…

Convert fields before sending to the page

I have a user dto class and i need to convert some of its properties before send it to frontend. UsedDto class Now, from my controller i get data like this In my case, before send data, i should convert boolean values (enabled, active) to string “Y” or “N”. How can i do this? Answer Yo…

How to deal with whitespaces when reading a file with a scanner

I am writing a program where I read data from a file name that the user inputs using a scanner. I am making a new object from each line of the file using the following code: This works correctly until my file for .txt files where there is no whitespace in between the lines but when there is a blank