-2

I am using JSONObject to create a new json in my Android Application. But I am experiencing a strange issue where I am observing that my json field names are getting replaced by letters like "a" : "value " , "b " : "value_1" , "c" : value2 " This works fine for smaller number of childs but as the number grows it distorts the json :

example json :

{
"Employees" : [
{
"userId":"rirani",
"jobTitleName":"Developer",
"firstName":"Romin",
"lastName":"Irani",
"preferredFullName":"Romin Irani",
"employeeCode":"E1",
"region":"CA",
"phoneNumber":"408-1234567",
"emailAddress":"romin.k.irani@gmail.com"
},
{
"userId":"nirani",
"jobTitleName":"Developer",
"firstName":"Neil",
"lastName":"Irani",
"preferredFullName":"Neil Irani",
"employeeCode":"E2",
"region":"CA",
"phoneNumber":"408-1111111",
"emailAddress":"neilrirani@gmail.com"
},
{
"userId":"thanks",
"jobTitleName":"Program Directory",
"firstName":"Tom",
"lastName":"Hanks",
"preferredFullName":"Tom Hanks",
"employeeCode":"E3",
"region":"CA",
"phoneNumber":"408-2222222",
"emailAddress":"tomhanks@gmail.com"
}
]
}

Corrupted output :

{
"Employees" : [
{
"a":"rirani",
"b":"Developer",
"c":"Romin",
"d":"Irani",
"e":"Romin Irani",
"f":"E1",
"g":"CA",
"h":"408-1234567",
"i":"romin.k.irani@gmail.com"
},
{
"a":"nirani",
"b":"Developer",
"c":"Neil",
"d":"Irani",
"e":"Neil Irani",
"f":"E2",
"g":"CA",
"h":"408-1111111",
"i":"neilrirani@gmail.com"
},
{
"a":"thanks",
"b":"Program Directory",
"c":"Tom",
"d":"Hanks",
"e":"Tom Hanks",
"f":"E3",
"g":"CA",
"h":"408-2222222",
"i":"tomhanks@gmail.com"
}
]
}

Is this a bug in the Android JSON object ? Any hints?

Raulp
  • 7,758
  • 20
  • 93
  • 155

1 Answers1

1

this issue based on proguard rules in app level gradle file to that value make false like below ..

    minifyEnabled false

other wise you can add key in your pojo class like

    @SerializedName("userId") // pass your json key
private String userId;