Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import android.support.v4.util.SimpleArrayMap;
  2.  
  3. import com.google.gson.JsonElement;
  4. import com.google.gson.JsonObject;
  5. import com.google.gson.JsonSerializationContext;
  6. import com.google.gson.JsonSerializer;
  7. import com.google.gson.reflect.TypeToken;
  8.  
  9. import java.lang.reflect.Type;
  10.  
  11. /**
  12. * Created by chris on 13/03/2014.
  13. * For Yoyo-Android.
  14. */
  15. public class SimpleArrayMapJsonSerializer implements JsonSerializer<SimpleArrayMap> {
  16.  
  17. public static final Type TYPE = new TypeToken<SimpleArrayMap>() {
  18. }.getType();
  19.  
  20. @Override
  21. public JsonElement serialize(final SimpleArrayMap src, final Type typeOfSrc, final JsonSerializationContext context) {
  22. if (src == null) {
  23. return null;
  24. }
  25. final JsonObject jsonObject = new JsonObject();
  26. final int length = src.size();
  27. Object k, v;
  28. for (int i = 0; i < length; i++) {
  29. k = src.keyAt(i);
  30. v = src.valueAt(i);
  31. jsonObject.add(String.valueOf(k), context.serialize(v));
  32. }
  33. return jsonObject;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement