How to use model values in dynamically model class to Retrofit requests?

Hock

In my application i want use Retrofit2 library for requests and i want set dynamically response model, i don't want set model into interface model!
I can set dynamically model and show me values from server into logCat.

But i don't know how can i this this values.

My codes :

public class ApiClient {
    private static final String BASE_URL = "https://example.com/";
    private static Retrofit retrofit = null;


    public static Gson gson = new GsonBuilder().create();

    public static Retrofit getClient() {

        OkHttpClient.Builder client = new OkHttpClient.Builder();

        OkHttpClient client2 = client
                .connectTimeout(10, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .readTimeout(10, TimeUnit.SECONDS)
                .build();

        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .client(client2)
                    .build();
        }
        return retrofit;
    }
}

public interface ApiInterface {
    @POST("api/server?mode=auctions_today")
    Call<ResponseBody> getMainAuctions(@Header("jwt") String jwt, @Query("page") int page, @Query("limit") int count);
}

public class TimerRecyclerActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private ProgressBar timerProgressBar;
    private List<Today> model = new ArrayList<>();
    private Adapter adapter;
    private ApiInterface api;
    private LinearLayoutManager layoutManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timer_recycler);

        api = ApiClient.getClient().create(ApiInterface.class);
        adapter = new Adapter(getApplicationContext(), model);
        adapter.setHasStableIds(true);
        recyclerView = findViewById(R.id.timerRecyclerView);
        timerProgressBar = findViewById(R.id.timerProgressBar);
        layoutManager = new LinearLayoutManager(getApplicationContext());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);

        Call<ResponseBody> call2 = api.getMainAuctions("", 1, 10);
        call2.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse
                    (@NonNull Call<ResponseBody> call2, @NonNull Response<ResponseBody> response) {
                if (response.isSuccessful()) {
                    try {
                        timerProgressBar.setVisibility(View.GONE);
                        Log.e("responseLog", "OK : " + response.body().string());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                }
            }

            @Override
            public void onFailure(@NonNull Call<ResponseBody> call2, Throwable t) {
                t.printStackTrace();
            }
        });

    }
}

LogCat :

E/responseLog: OK : {"res":{"today":[{"id":20906,"product_id":2,"base_price":3550000,"offer_number":60,"bid_number":3,"start_date":"2018-06-17 10:55:03","duration":2,"end_date":null,"visit":0,"capacity":40,"input_price":0}}

But i don't know how can i use this values.
For example : i want add Today list into model with model.addAll(); but i don't know how can i it?

How can i it? can you help me?

Alexander Bratusenko

You have bad formed Json, otherwise you could use Gson for parsing you model value.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to build a model class dynamically in Spark and Scala

How to retrofit a fasttext model?

Retrofit 2 without Model Class

Dynamically use model in laravel

How do I map Retrofit response to Data Model Class?

How to use the model/POJO with android databinding, room and retrofit?

Retrieving model class dynamically in CBV

How use Maps in Model Class/ Data Classes

How to use class model with Redux (with a Mobx option)

How to filter model results for multiple values dynamically in django

How to bind values dynamically in v-model in vue 2

How can I add model list values dynamically in MVC?

Yii2: How to add validation rules to the model class dynamically?

Retrofit Unable to Parse JSON from Model Class

Sending model class with Boolean values to retrofit endpoint that doesn't sometimes accept that boolean value

How to Instantiate a model class in another model class?

How to model an enumeration class?

How do I use abstract model field values as default values in child model fields in Django?

How to declare model class in react native and pass whole model class in second screen by use of react navigation

Django model dynamically query ManyToManyField for values

Dynamically creating ng-model values

Spring : how to get values from properties file in Model class

How to set json values to a model class directly in swift

How to get or display list values available in the business or model class

How to store Values in Array/NSMutableArray From Model Class Dictionary?

How to create a model class for dynamic keys and values in firebase database in android

How to assign values to a model class from a list in Flutter?

Dynamically add accessor methods in Laravel Model Class

How to parse nested Object model in retrofit