TLDR
I want a kotlin utility to call a 'GET' method on a restful API. Must I-the-programmer define a class that matches exactly the json output? Can I skip fields, so that the 'value/return object' class includes some of the returned fields, but not others?
Background
I'm new to kotlin and switch-hitting between python and kotlin.
I'm writing a utility to get data from a restful api. The vendor provided documentation and examples.
In python, the 'get' method would return a 'Map of maps'. The kotlin way, in contrast, is to return a 'well-defined' object.
I-the-coder can 'poke around' with this 'returned object' for the 'information I need'
Example
For example, let's say I want to 'get customer' from the rest api and my-utility only wants these fields:
- 'name'
- 'member since' date.
But let's say the 'get customer' json object includes a whole-bunch-of-info I-the-programmer don't care about:
- "order history" (each entry in the 'order history' list is itself a complex object)
- "customer preferences"
In kotlin: do i need to define a class that matches each and every field on the returned object? Can I define only the 'fields I care about' and have the 'json parser/object mapper' ignore all other fields?
Vs SOAP
Back in the day (e.g. 2006), applications providing SOAP services would generate java-client classes from the WSDL. Does the kotlin programmmer need to do the equivalent for restful programming?
Json Libraries
I didn't mention any specific parser (jackson, gson, klaxon) because I'm more interested in the general approach and assumed the "kotlin side" would be similar fo reach.