Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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
16
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

Hi,
I need to work with int64 that are no longer than 16 digits and they are generated by an application I cannot control. Just before processing them I want to check wether they are equal or bigger than 17 digits and then limit them to 16 max. I have a small util that checks the length of the int:



Having checked the length, I am doing the following:



my issue is that I cannot always remove 3 as the int64 generated might be already of length 17 and I need to only remove 1 digit. Can you help? Is also advisable to convert it to a string operate on the string and convert it back?


Thank you
3 weeks ago
Go

Rob Spoor wrote:This issue doesn't appear if you use encoding/json to parse to a struct that has an int64 property. For instance:

Output:

The map contains a floating point number which has the issue you see. The struct does not.



Thank you for your reply, appreciated. Yes, indeed, when unmarshalling with a struct containing the int64 value does work, however the issue is that I am dealing with several models and my utils needs being generic (and it is in fact shared across severall apis) and therefore I cannot pass a specific struct. I indeed need to use in the map. Is there any other way this can be solved? Thank you
3 weeks ago
Go

Geane Norm wrote:Hi,
I have been struggling with an issue with the usage of int64 inside a struct. When parsing into Json in Go and from the 17th digits onwards I have noticed that it starts round the int64 up. For example: 2882795323592627689 => 2882795323592627700

My understanding is that json "numbers" get treated as floating points and therefore they are limited to 53 digits of integer precision. I cannot change my original struct and from the client point of view I still need to have a int64 and it is imperative to have it the same as it identifies a specific request. Can you help with this? This is my current implementation:

Function to convert []bytes to int64:



This, in turns, is used inside a function that construct the struct mapping and does the Json unmarshalling:




I have consulted various resources, but with no joy as my main issue seems to be to be able to treat "in a special way" only the int64 in the struct:

https://stackoverflow.com/questions/16946306/preserve-int64-values-when-parsing-json-in-go
https://github.com/golang/go/issues/5562
https://play.golang.org/p/gHEj8WHuTx

Any idea, can you help?

Thank you



I have found this: https://github.com/square/go-jose/issues/351

Is this even an issue that can be fixed or I will always face rounding up for in64 bigger than 17 digits? The issue I have is that this needs being rather generic for a multiple of fields one of which unfortunately is int64 and exceeds 17 digits, therefore the situation is complicated by the usage of the generic. I have attempted at using my own field in a custom struct, but I cannot make it generic enough
3 weeks ago
Go
Hi,
I have been struggling with an issue with the usage of int64 inside a struct. When parsing into Json in Go and from the 17th digits onwards I have noticed that it starts round the int64 up. For example: 2882795323592627689 => 2882795323592627700

My understanding is that json "numbers" get treated as floating points and therefore they are limited to 53 digits of integer precision. I cannot change my original struct and from the client point of view I still need to have a int64 and it is imperative to have it the same as it identifies a specific request. Can you help with this? This is my current implementation:

Function to convert []bytes to int64:



This, in turns, is used inside a function that construct the struct mapping and does the Json unmarshalling:




I have consulted various resources, but with no joy as my main issue seems to be to be able to treat "in a special way" only the int64 in the struct:

https://stackoverflow.com/questions/16946306/preserve-int64-values-when-parsing-json-in-go
https://github.com/golang/go/issues/5562
https://play.golang.org/p/gHEj8WHuTx

Any idea, can you help?

Thank you
3 weeks ago
Go
Thank you both, it helped a lot! Out of curiosity, when I rename the automatically created "unnamed workspace", can this be saved anywhere?  Does it have to be at a precise location?

Thank you
2 months ago
Go
Hi all,
I am a newbie to Go and I am trying to find my way around especially when using it with Visual Code (which I barely used before). By typing (I work in mac), I can see that my is in:



However, I want to keep all my code inside , therefore when I stand up Visual Code I have created a workspace and added each project as a folder. Is this the right way to do it? Do I need to have my code in the same location as my ? Is there a good step by step guide on how to work with Go and Visual Code? Do I need to have a workspace per project?

Thank you

2 months ago
Go

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,

7 months 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.

7 months 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
7 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.

9 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
9 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
9 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
9 months ago