SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun Any?.toHashMap(): HashMap<String, RequestBody> {
  2.     val map = HashMap<String, RequestBody>()
  3.     if(this == null){
  4.         return map
  5.     }
  6.    
  7.     for (field in this.javaClass.declaredFields) {
  8.         val temp = field.isAccessible
  9.         field.isAccessible = true
  10.  
  11.         val fieldName = try {
  12.             field.getAnnotation(SerializedName::class.java).value
  13.         } catch (e: Exception) {
  14.             field.name.toString()
  15.         }
  16.  
  17.         map[fieldName] = RequestBody.create(MediaType.parse("text/plain"), if (field.get(this) == null) "" else field.get(this).toString())
  18.         field.isAccessible = temp
  19.     }
  20.  
  21.     return map
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top