amoose20 / indieProject

1 stars 0 forks source link

Week 8 ready for review #4

Open amoose20 opened 1 year ago

amoose20 commented 1 year ago

@pawaitemadisoncollege week 8 is ready for review. Screenshots of this class and the passing tests are in the screenshots directory. This link will take you directly to the TestServiceClient class: https://github.com/amoose20/indieProject/blob/ca1b7754ad3ad2111b00e088707f3a9dbc0e3055/src/test/java/TestServiceClient.java

What were your key learning points/takeaways?

-Key learning point was how to consume and use API's in applications. Seeing how API's respond to requests and how to use those responses was really enlightening. I feel now that I am working with information provided by the API, the functionality of my application can begin to take shape.

What challenged you?

-I was running into some initial issues with testing the generated POJO based on the JSON response from the API. The specific error I was getting was a 'jackson.MismatchedInputException' I did some digging/google'ing and discovered that when using the JSON response from the API, including the square brackets at the beginning and end of the response will create an additional class with one getter/setter returning a List of the other class created. In my case, the two classes were Sports and SportsItem. Sports returning a List, SportsList contained the methods for the actual data for the sports such as Title, Description, etc.

When testing the Sports and SportsItem generated classes, I am realizing I wasn't refactoring the assertions to account for testing an list. Instead of adjusting the tests, I recreated the POJO eliminating the starting and ending square brackets. As a result, the generator created only one class, equivalent to the SportsItem class. There was no class with only one getter/setter returning the List.

However, I still ran into the 'jackson.MismatchedInputException' errors when running the assertions. The solution I found was to change the type of the object returned from mapper.readValue() to an array and then create assertions to test that array. See the code snippet here:

https://github.com/amoose20/indieProject/blob/b10956f1e6852422e83dd3c35be5ac4675ea6fbd/src/test/java/TestServiceClient.java#L21

So I believe both methods of the POJO generated classes would work. I just needed to refactor my initial assertions to test an list, which I eventually did have to implement anyways because of changing the return type of mapper.readValue() to an array. Learning the hard way sometimes! 😅

What problems did you solve and what resources did you use to solve them?

-I google'ed the stack trace errors and used this page's method of changing the return type of mapper.readValue() to an array.

https://facingissuesonit.com/2019/07/18/com-fasterxml-jackson-databind-exc-mismatchedinputexception-cannot-deserialize-instance-of-xyz-out-of-start_array-token/

pawaitemadisoncollege commented 1 year ago

Hi @amoose20! Whew!!! Sounds like a lot of hard work and learning came out of week 8! Drilling down through the objects to the object you actually care about can be tricky.