Creating a custom Callback for Retrofit

I am using Retrofit and Otto in my app for web service calls. I want to assign an id for each request made so I made a custom Retrofit callback like this

public class RetrofitCallback<T> implements Callback<T> { private static int _idCounter = 1; public int requestId; private Bus eventBus; public RetrofitCallback(Bus eventBus){ this.requestId = _idCounter; this.eventBus = eventBus; _idCounter++; } @Override public void success(T data, Response response) { // problem.. data is not the type I expected. please see below RetrofitRequestSuccess<T> message = new RetrofitRequestSuccess<>(requestId, data, response);; } @Override public void failure(RetrofitError error) { RetrofitRequestFailed message = new RetrofitRequestFailed(requestId, error);; } }

The RetrofitRequestSuccess class

public class RetrofitRequestSuccess<T> { public T data; public int requestId; public Response response; public RetrofitRequestSuccess(int requestId, T data, Response response) { this.requestId = requestId; = data; this.response = response; } }

I then use the callback as follows

int requestId = 0; // activity level scope RestAdapter restApiAdapter = new RestAdapter.Builder().setEndpoint(ENDPOINT).build(); RestAPI restClient = restApiAdapter.create(RestAPI.class); RetrofitCallback<List<Order>> callback = new RetrofitCallback<>(BusProvider.getBus()); restClient.getOrders(callback); requestId = callback.requestId;

Otto subscribed method

@Subscribe public void onHttpResponseReceived(RetrofitRequestSuccess message) { if(message.requestId == requestId) { List<Order> ordersList = (ArrayList<Order>); } }

The problem is I never get List of Order objects in No matter what type I pass when I create the callback, the always contains a List of Gson's LinkedTreeMap objects. How can I make it to return the correct type? Any help would be greatly appreciated!

Category:android Time:2018-12-17 Views:1

Related post

  • How do you create a custom attribute for MS Test? 2008-09-22

    If you want to create a custom attribute for MS test (say [Repeat(3)] how would you do that? --------------Solutions------------- I don't think you will like the answer: there is no supported way. However, there is a codeplex project MSTestExtensions

  • How can I create a custom Property for my assembly? 2008-10-10

    How can I create a custom property for my .Net assembly which would then be visible under the Details tab in Windows explorer? Something to sit parallel with "File Description", "Type", "Product Version"... etc Update: To quote my comment to Lars ...

  • Help with creating a custom ItemRenderer for Flex 4 2010-05-21

    I'm trying to create a custom ItemRenderer for a TileList in Flex 4. Here's my renderer: <?xml version="1.0" encoding="utf-8"?> <s:ItemRenderer xmlns:fx="" xmlns:s="library://" xmlns:mx="li

  • How to Create a custom validation for my entities 2011-01-04

    I would like to know if this is possible to create a custom validation for my User Entity. I Want to verify if the username is unique. If the user Already exist, I don't want to save it and show a warning. I Read about Data Annotation inherits but I'

  • Creating a custom layout for preferences 2011-05-31

    I'm trying to create a custom layout for managing preferences. I know there is the standard and recommended layout provided by PreferenceActivity, but if I want to add, say, a Button, how do I go about doing that? I plan to design the application so

  • Creating a custom signal for when a user activates his account 2011-06-30

    I am trying to create a custom signal for when the field auth_user.is_active becomes 1. I looked at Django's docs on signals, but was having trouble understanding how to implement custom signals. When a user account becomes active, I want to execute

  • Create a custom action for rules in Outlook 2011-08-18

    I would like to create a custom action for rules in outlook 2007 or 2010. Can I have an example of any type of code that create any custom action so from that I can have an idea of how to create my custom action (that does its specific action)? -----

  • How to create a custom toolbar for SyntaxHighlighter 3.0.83? 2011-12-27

    I am trying to create a custom toolbar for SyntaxHighlighter 3, but have been unable to figure out how to do so. I've seen custom toolbars before but only for version 2. I don't care if it is either a text-based or image-based toolbar so long as it c

  • Who to create a custom method for data insert operation in silverlight? 2012-02-16

    I am using silverlight WCF Ria service to handle database related operations in my application. I do have a table Post(Id int identity,Title varchar(50), Content varchar(50), Date datetime, Comments varchar(50) ); I can easily use public void InsertP

  • How to create seperate custom taskpane for individual word document 2012-03-21

    I created a custom addin for word document. Created a toggle button in ribbon. When user click on button a custom taskpane displays and again if user click on button taskpane will be hidden. Now my problem is that the same taskpane is used for all op

  • Can MS Project 2010 create a customized filter for more than two things? 2013-09-14

    I'm trying to create a customized filter for tasks that are critical, milestones and are incomplete. The critical and milestone filters work fine, but when I throw in the incomplete, it ignores it. I must be doing something incorrectly, but I don't k

  • Is there a way to create a custom icon for my excel worksheet? 2014-10-23

    I'd like to create a custom icon for an excel worksheet - I'd like to change the icon that a user double clicks on the desktop to open the file. Is there a way to do this without it changing the settings on all excel files? --------------Solutions---

  • can I create a custom key for restart (windows) key on the Micsoft Ergo 4000 keyboard? 2014-10-27

    Original Title: MS Ergo 4000 kb. Hey Should be a easy one. On my old and dead logitech keyboard had a restart (windows) key. can I create a custom key for this on the 4000? I looked in the keyboard software but found no option. Thanks P.S. Why is it

  • unable to create add custom domain for my emails 2014-10-30

    Hi, I'm getting currently an error saying the domain can't be creates as some keywords might be blocked. Domain: As I have a yellow error saying contact technical support. I made some tests & seem any domain what ever the extens

  • How to create a custom template for WCSF (.NET 2.0)? 2008-09-19

    I'm new to the WCSF and can't seem to find anything related to "building a custom template" for creating the views/presenters/code-behinds/etc with your own flavor ... Can anyone point me in the right direction? --------------Solutions------------- y

  • Is it a good idea to create a custom type for the primary key of each data table? 2010-01-11

    We have a lot of code that passes about “Ids” of data rows; these are mostly ints or guids. I could make this code safer by creating a different struct for the id of each database table. Then the type checker will help to find cases when the wrong ID

  • jQuery validationEngine plugin - custom callback for datepicker input fields 2010-04-09

    I'm using this jQuery validationEngine but I'm having a problem validating input fields which are transformed using Jonathan Leighton's datepicker. I need to validate that two dates are the same, so i have a custom callback (validateDOB) to check thi

  • Creating a custom InputScope for Windows Phone 7 2010-10-06

    Where can I find a tutorial for creating a custom InputScope? I'd like to create a custom keyboard that displays only the numbers 1-9 on the onscreen keybord (no symbols). --------------Solutions------------- You cannot create custom input scope, her

  • Best way to create a custom view for every list item 2010-11-04

    As I am reviewing and prototyping my android project, I noticed that there is a view that has a list of items that are very customized. I have figured out most of my tools that I plan to use but I need some advice. I have a list of items which can co

Copyright (C), All Rights Reserved.

processed in 0.594 (s). 13 q(s)