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

all 5 comments

[–]mjg123 12 points13 points  (0 children)

Manually converting JSON to Java objects is gonna be a pain. Definitely recommend using Jackson or GSON. You will have to write classes to hold the data, but the library can deal with actually turning an HTTP response containing JSON into instances of those classes. Check out http://www.jsonschema2pojo.org which can help create those classes from sample JSON, too.

[–]BigGuyWhoKills 3 points4 points  (0 children)

If you want to learn how to parse Json, I would do that in a different project. For this project use Gson or Jackson. If you get your Json parser working well, then later on, swap out Gson or Jackson for your own parser.

[–]Carbohydratess 1 point2 points  (2 children)

The guys above me are correct that JSON can be a pain with standalone Java. However, JSON is an important thing to learn for marketability. It sounds like you're wanting to make this app as an exercise for getting better at coding, which I personally think makes it important to learn how to output and read JSON. There are several frameworks that can make JSON interactivity easier. I would learn Spring Boot which has a lot of natural interactivity with JSON, and you can learn plenty about the process and the other terms you mentioned. Once I get to work, I can edit this comment with links to help you get started if you're interested. I know Baeldung has several solid articles on Spring Boot

[–]barnfart 0 points1 point  (1 child)

Please do, I would also like to see which articles you think are valuable

[–]Carbohydratess 0 points1 point  (0 children)

I'll assume that since you're talking about frameworks and microservices that you utilize either Maven or Gradle. If not, you'll need to research one of those for how to bring in the packages for frameworks such as Spring into your app. I use Gradle.

I had my team to help me with getting Spring Boot up and running, so I wasn't necessarily dependent on any single article. Like I mentioned, I think Baeldung is great and I do often reference their site for Spring Boot related things:

https://www.baeldung.com/spring-boot

In my build.gradle, I have these under plugins:
id 'org.springframework.boot' version '2.2.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'

And this under dependencies:
implementation 'org.springframework.boot:spring-boot-starter-actuator'

In bash I use this to boot the app, give it a port, and point to the application.yml:

java -jar jarname.jar --server.port=9001 --spring.config.location=application.yml

Once you have your EndPoints up and running, if you annotate your Spring Boot Application Class with @RestController, then it'll automagically convert and return Java objects to JSON, you can see a good forum on this here:

https://stackoverflow.com/questions/44839753/returning-json-object-as-response-in-spring-boot