1

i want to ask about Retrofit 2.0

all this time, i knew Retrofit only with GSON Converter and get the object.

But i dont know how to get the data with API like this https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty

i'm trying to display all top stories and get the object after i load all the top stories first.

i only know with old school style like this: http://pastebin.com/JMpwjH8H

  • are you asking how to use Retrofit, or how to use Retrofit without [POJOs](https://en.wikipedia.org/wiki/Plain_Old_Java_Object)? – roarster May 09 '16 at 16:04
  • i dont know exactly what im asking because that API response only like Article ID, and i dont think it can use POJO – Riki Rikmen May 09 '16 at 16:06

2 Answers2

2

I'm pretty sure for your example you can just set the response type as a list of Integers like this:

public interface ApiInterface {
    @GET("topstories.json?print=pretty")
    Call<List<Integer>> getTopStories();
}

Using a POJO would be too complex for what is essentially, just an array of Integers.

roarster
  • 4,058
  • 2
  • 25
  • 38
  • This is the Interface which is the part of Retrofit that you would change to allows responses without POJOs. If you have the rest already implemented then yes, using the code above is possible. If you're looking for a guide to using Retrofit you can find that on [their website](http://square.github.io/retrofit/). – roarster May 09 '16 at 16:05
  • im sorry it cant, i dont know why.. please help me.. this is my code http://pastebin.com/g0YM3xgM http://pastebin.com/hghhise7 – Riki Rikmen May 12 '16 at 16:02
0

First of all, you should know whether it is POST web service or GET web service. what parameters you will be giving to get the desired response and how would you store the response in POJO. This tutorial will help you with all basic thing that you require for integrating web services

Mrugesh
  • 4,381
  • 8
  • 42
  • 84
  • actually, i dont even know how to create a class with that kind of this API https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty , what i mean is this result cant store in POJO – Riki Rikmen May 09 '16 at 15:53
  • first of all , you should be thorough with creating POJO from JSON/XML response. [link] http://www.jsonschema2pojo.org/ [link] will help you build such classes – Mrugesh May 09 '16 at 15:56