#Retrofit question

1 messages · Page 1 of 1 (latest)

stable glen
#

hi, i'm working on an app using retrofit to fetch json from get request.
retrofit would then put the json in the data class i created.
my question is, is it possible to ask retrofit to create this data class from a string (or var json object) without having to use get request?

odd fiberBOT
#

<@&1008423204219531294> please have a look, thanks.

odd fiberBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

cedar hemlock
#

can you say a bit more?

#

are you just trying to hook into how retrofit handles json?

stable glen
#

Well i know the basics of retrofit, i used it in 2 previous small projects.
I used it to get a json from crypto coins api for example. I would create a list of data classes with vars like name, usd value, image url etc.
Then I was able to access the json keys something like this:
View.text = cryptocoins[0].name
If you understand

So is it possible for retrofit to create this list of data classes without the api get request?
For example from a string or a json file in the project

stable glen
#

Well I was helped by chatgpt so I will post the answer here

val jsonString = "{\"name\": \"John Doe\", \"age\": 30}"

// Create a ResponseBody object from the JSON string
val responseBody = ResponseBody.create(MediaType.parse("application/json"), jsonString)

// Use Retrofit's converter to convert the ResponseBody to a User object
val user = UserConverter().convert(responseBody)

odd fiberBOT