This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General forum!

Geane Norm

Ranch Hand
+ Follow
since Feb 01, 2016
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
14
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Geane Norm

Himai Minh wrote:You may need to use a Json parser such as JSONParser to parse your original Json object and collect the data.
Then, use your data to create a new Json object.


Reference:
https://www.geeksforgeeks.org/parse-json-java/



Hi,
thank you for your reply. So, as it stands, I can successfully consume the third party service for which I created a Dto with all expected @JsonProperty per field. I have also created an entity for the expected new format and its Dto. What is the best to go about? Can I convert the initial Dto with the new format one and in my Controller I will return the new format? Would you happen to have any example I can check?

Thank you,

1 month ago
Hi,
I have a task whereby I need to integrate with a third party API. I am planning to do something along these lines: https://spring.io/guides/gs/consuming-rest/, meaning using Spring’s RestTemplate to retrieve the response of an external API from within my Spring Boot application. Until this all good, but the second step is to "re-construct" aka convert the existing response to a new format.

For example, the original response from the 3rd party API is something like:




and the expected customised output should look like:



Expected changes are both in format/data structure (e.g. field_3_1 is now a field inside an array) and the field naming convention (e.g: "id" becomes "application_id"). Is there any Spring library/class I can use for easily make the conversion? I will create a new model class with the customised response, but I am not sure about the approach for re-structuring the data. Can you help? Is there any example I can look it up?

Thank you,

G.

1 month ago
Hi,
as a developer I am used to write Unit tests as well as Integration Tests. I have been working with a microservice architecture in which there are around 20 single responsibility services/functions. Each service is tested (Unit Tests and integration tests) and contracts are clearly written in terms of expected input and output, but we have never actually written Integration tests at the "microservice architecture level". Are they any recommended approaches or strategies? Anything that should be taken into account when testing integration between multiple functions/services?

Thank you
2 months ago
Hi,
I have a requirement whereby I need to construct a GET request from within my Java program that get from a publicly available URI a JSON of this shape:



I then need to convert the resulting response into an InputStream for some additional processing. I have tried a few things, mostly from here: https://mkyong.com/java/how-to-send-http-request-getpost-in-java/

The issue I am encountering is that by the time I get to the InputStream I always face a closedStream issue:




Where am I going wrong and most importantly, is this a good approach?

Thank you,

G.

3 months ago
I have had to convert a couple of derived (keyword-based) queries into corresponding native ones (Postgres sql) and I have noticed the ORDER BY clause does not seem to work. Here are two sample queries:


And


After a number of tests I came to the conclusion that native queries do not seem to handle well ORDER BY clauses and this causes an issue with my current application. Is there any way to handle them with native queries? Any potential alternative? I would also be happy with converting them back to derived queries.

Thank you
4 months ago

Tim Moores wrote:There are freely available currency conversion WS out there. Either make your WS a proxy for one of them, or retrieve the rates you need to support in regular intervals (might once a day be sufficient? If not, maybe once per hour) and perform the conversion in your WS. I would advise the latter, as the former adds a network round-trip on top of the round-trip to your WS - not a good solution. (It would also raise the question: why use your WS if the client could simply use the other one instead?)



Thank you once again. Do you have any particular suggestion for the currency conversion service? I have found a few of them here: https://stackoverflow.com/questions/3139879/how-do-i-get-currency-exchange-rates-via-an-api-such-as-google-finance, but it is a new territory for me. From an implementation point of view, shall I then remove the repository itself that is of no use and create a response call that would call directly whatever api I will eventually choose? Is this what you meant by just retrieving the rates at regular intervals? I would not want to implement an additional layer when I can simply query a reliable service and use the response for my own WS. Or is there any other good approach for using an external api from within your own Spring app?

Thank you,

Regards
4 months ago

Tim Moores wrote:Just to make sure: the WS returns the exchange rate, and you want that WS to update its data in the background, independently from any client invocation?

What do you mean by "check the rate" - retrieving it from some other remote service?

Given that this is a single data point, I think using Redis would be overkill.

And I don't really see a pub/sub design, given that you're building a WS.



Hi,
thank you for your reply. I would simply like the WS to return the exchange rate, nothing more. Are you suggesting that I do not really need to have a repository implementation? Regarding the "check the rate" question, that is a good one. Is there any existing currency converter I could be using for the actual conversion?

OK, I was mislead by the fact that the WS needs to return the rate value "continuously" and that to me suggested that there should be a listener of some sort.

Thank you
4 months ago
Hi,
I need to develop a service that checks constantly the currency exchange rate between Euro and Dollar. I have started thinking about its basic implementation and I am going to do the following:

- Create a Spring Boot application including:
  • Exchange Entity;
  • Exchange Repository;
  • Exchange Controller with one endpoint getting the latest exchange rate as well as historical rates by using optional parameters such as startDate to endDate;
  • Exchange Service


  • I have a question regarding the current plan. Amongst my requirements the service needs to check constantly the rate and to me this suggests that I need implementing publisher/subscriber architecture. I was thinking to use https://spring.io/projects/spring-data-redis and implement a listener.bWhat is your view? I welcome any advice to improve upon my current planned implementation.


    Thank you,

    4 months ago

    Dave Tolls wrote:With SQL you bind variables to values, not column names or chunks of SQL.
    So that query won't work anyway.



    Thanks, is this even possible? Is there any way to achieve that?
    6 months ago
    I have a requirement whereby my native query would need to have an ORDER BY on potentially multiple sorting fields and directions. I have a native query in my repository that looks something like this (it has been made much simpler than the current one):  



    My issue is that `?1` can ideally be matched to multiple fields in my `someTable` whose data types are different. For example, it can be an ID of type UUID as much an integer, etc. Is it possible to perform sorting on multiple fields (over 15 potential ones) and attached directions? I am getting the values of the sorting fields and corresponding directions from a method querying an external service and getting such values from the body of a `ResponseEntity<Any>`.

    Thank you
    6 months ago
    Hi,
    my requirement is to be able to loop through the following JsonNode and its elements:



    Each iteration should present a JsonNode with its elements until no JsonNode object is found. I have started with the following:



    Is this a valid approach? Ultimately, I would like to get each element in the JsonNode with its associated values. Ideally, my function should return a JsonNode. Down the line, I would also like to use the id in a repository query, so what would be the best approach? Shall I convert it into a Map? Something along these lines:



    Can you help? I am not quite sure how to go about it.

    Thank you
    6 months ago
    Hi all,
    I have the following enum:




    Each of the class (e.g. ClassOne) is a data class implementing interface MyClass<Entity> as follows:



    My issue is that I have a method taking each of the mapped classes as an argument and I am trying to find a way to make it more generic by getting the corresponding class per enum. I have written the following:




    which correctly returns the mapped class, however i am struggling to correctly using it here:



    Essentially I want to avoid replicating the method signature by not having to pass in the concrete mappedClass as a parameter. The issue is that the returns , while the savedEvent is expecting the concrete data class . I have attempted at casting it to MyClass to Entity, but with no luck. Can you help? As it stands, I now have 3 identical methods whose only difference is the abovementioned argument/parameter.

    Thank you for your help

    9 months ago

    Liutauras Vilda wrote:Hi Geane,

    I find it confusing to understand the task. I have some ideas what you might want to do, but I have to admit that code looks confusing at the moment.

    1. First, I think your chosen variables are misleading or not intuitive.

    1.1.

    So this one the way I understand is, given the Status A, to which status it might go to from Status A, right? Not sure why you call it expectedStatus.

    I'd call them along the lines: currentStatus -> nextStatus or transitionStatus, because having expectedStatus one may think, ok, it was given start Status A, but actually was expected Status B - see where the confusion may arise?


    1.2

    But what actually you have inside, is a list of States not Statuses.



    2. In the other snippet of code you have

    What this one supposed to achieve? As currently it does nothing in my understanding.


    So if you ask me. I'd make those things clearer and delete parts of code which are not used, that way I'd find easier to understand where things fall apart, although lately I'm not that proficient in Kotlin.



    Hi, thank you for your reply. So my map will look something like this:



    As you can see a list of values can match a key (e.g. C=[B, E, D]), however the validator works with pairs. My expected result is to be returned with TRUE every time a pair is matched. Can you help? I am not really sure what I am missing here

    Thank you


    10 months ago
    Hi,
    I have the following:



    I would need to write a validator that takes the initial status and return the allowed values. Although relatively straightforward, I cannot wrap around my head as why the below implementation results in some of the expected mappings to fail:





    Can you help?
    10 months ago