Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement