Created
November 18, 2015 05:04
-
-
Save GulajavaMinistudio/22ee0e12bc0efa68f2cf to your computer and use it in GitHub Desktop.
JacksonJrResponseArrayConverter class for parsing JSON Array response from server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gulajava.pilkadayuks.internets; | |
import com.fasterxml.jackson.jr.ob.JSON; | |
import com.squareup.okhttp.ResponseBody; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import retrofit.Converter; | |
/** | |
* Created by Gulajava Ministudio on 11/18/15. | |
*/ | |
public class JacksonJrResponseArrayConverter<T> implements Converter<ResponseBody, List<T>> { | |
private Class<T> clazz; | |
public JacksonJrResponseArrayConverter(Class<T> tClass) { | |
this.clazz = tClass; | |
} | |
@Override | |
public List<T> convert(ResponseBody value) throws IOException { | |
try { | |
return JSON.std.listOfFrom(clazz, value.bytes()); | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
return new ArrayList<>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment