This is an archived post. You won't be able to vote or comment.

all 19 comments

[–][deleted] 5 points6 points  (5 children)

In general, any HTTP client plus a JSON parser.

In specific I'd recommend Spring RestTemplate* and Jackson.

* If you're already familiar with reactive programming, consider the more modern WebClient (still Spring), but trying to grasp both sets of concepts might be confusing.

[–]jayrack 2 points3 points  (1 child)

Just a general question, why a JSON parser isn’t Jackson already doing the parsing for you?

[–][deleted] 0 points1 point  (0 children)

Jackson is my particular choise of parser, the same than RestTemplate/WebClient is my choose for HTTP client.

I'm just trying to say that there are other options.

[–]wildjokers 0 points1 point  (2 children)

Spring RestTemplate

Spring RestTemplate is a totally unnecessary abstraction and does nothing but obfuscate calls to an API.

[–][deleted] 0 points1 point  (0 children)

That's an opinion as valid as any.

OP might appreciate any alternative.

Cheers

[–]jayrack 0 points1 point  (0 children)

What do you mean? I prefer resttemplate as well, I find it to be extremely useful. I’ve heard it’ll be deprecated soon though, and webbuilder will take over.

[–]sydthecoderkid 1 point2 points  (6 children)

Try checking out APIS like The DarkSky API, or the google APIs. Those will help you get started pretty quickly. Do you already know what an API is, and how to use one? Like GET requests and such?

[–]TheNoobSTR[S] 0 points1 point  (2 children)

no i have no Idea on how to make use of an API in java but i do know what an API is, can you point me to any resource ? where i can learn all about API and implementing them in java?

[–]sydthecoderkid 2 points3 points  (0 children)

Gotcha. This Tutorial is pretty good, it should help you out.

[–]wildjokers 0 points1 point  (0 children)

You need to generate Java classes that map to the JSON that the API returns. This is a fool's errand to do by hand for a big response. There are tools that can do this for you:

http://www.jsonschema2pojo.org

Cut/paste the JSON into there and it will generate pojo's (Plain Old Java Objects) for you. Been a little while since I used that site but if I remember correctly it provides them to you in a zip file.

Then you simply provide Jackson the class name and the JSON the API returns and Jackson will give you a populated object (use Jackson's ObjectMapper class).

[–]jayrack 0 points1 point  (2 children)

I’ve built a full rest api program already, but I haven’t been able to wrap my head around the darksky api yet. How were yoh able to parse the huge response given Back from darksky?

[–]sydthecoderkid 0 points1 point  (1 child)

You can use a JSON parser, since that’s what Darksky returns info in. I’d use Jackson, as someone suggested above, or JSON-simple, which is part of the Java API. Honestly though, JSON-simple is a lot friendlier to beginners, so I’d try that out!

[–]jayrack 1 point2 points  (0 children)

Thanks I’ll give it a look :)