Итак, у меня есть GSON JsonObject, который имеет в основном строки, но когда я передаю ему список, он отображается как строка, а не как список, как предполагалось.
Я создаю список в предыдущее действие, преобразуйте его в строку, а затем передайте во второе действие в виде строки и преобразуйте обратно в список для использования в JsonObject. Пожалуйста, смотрите ниже
{
"animal_product_code": "323",
"initials": "Mr",
"first_name": "Manos",
"last_name": "Mgx",
"address": "Straat",
"house_number": "9",
"zipcode": "2013BR",
"residence": "plaats",
"date_of_birth": "1977-04-14",
"gender": "M",
"email": "manolacopix@gmail.com",
"phone_number": "0771042286",
"petplan_order_number": "S2C.983365943182",
"tcs_vnumber": "",
"animal_nickname": "Dogger",
"animal_gender": "F",
"animal_chip_number": "321313123123123",
"animal_birthday": "2017-01-23",
"animal_age": "2017",
"animal_breed": "Pure",
"animal_race_id": "1",
"animal_zipcode": "2013",
"animal_health_q1": "Ja, gelukkig wel",
"animal_health_q2": "Nee, geen medische zorg gehad of geadviseerd",
"animal_type": 1,
"insurance_premium": 1,
"insurance_provider": 1,
"iban": "NL12322222222222222",
"premium_amount": "16.59",
"premium_deductible": "0.00",
"additional_coverages": "[\"[{price:12.27\",\"name:chemo}\",\"{price:4.24\",\"name:crematie}]\"]"
}
Preferred output :
{
"residence": "Hoofddorp",
"animal_nickname": "TESTAANVRAAG",
"animal_object_code": "63",
"last_name": "Bruin",
"iban": "NL91ABNA0417164300",
"animal_health_q1": "Nee",
"zipcode": "1234 AB",
"animal_gender_id": "1",
"animal_health_q2": "Nee",
"address": "Skagerrak",
"animal_race": "Alaska",
"animal_filter_code": "179",
"premium_amount": "15.58",
"animal_product_code": "325",
"initials": "S",
"phone_number": "0612345678",
"animal_necessary_followup": "TEST",
"animal_gender": "M",
"date_of_birth": "1989-05-28",
"email": "steffan.bruin+99@gmail.com",
"card_amount": "0",
"animal_breed_id": "2",
"animal_birthday": "2019-12-31",
"tcs_vnumber": "",
"animal_age": "2019",
"insurance_provider": 1,
"petplan_order_number": "S2C.8ABE520D93B5",
"additional_coverages": [{
"name": "crematie",
"price": "2.7109"
}, {
"name": "reisverz",
"price": "2.9694"
}],
"first_name": "Steffan",
"animal_breed": "Pure",
"animal_other_complaints": "TEST",
"gender": "M",
"animal_zipcode": "1234 AB",
"animal_current_complaints": "TEST",
"premium_deductible": "100.0",
"animal_chip_number": "123465789012345",
"animal_type": 3,
"animal_race_id": "1",
"animal_vet_name": "DIERENKLINIEK",
"house_number": "69",
"insurance_premium": 1
}
Код:
//here I convert String back to a List
items = Arrays.asList(additional_coverages.split("\\s*,\\s*"));
//here I added to the object
Gson gson = new Gson();
JsonObject petplanUser = new JsonObject();
petplanUser.addProperty("additional_coverages",gson.toJson(items));
Любые предложения или решения о том, как добиться правильного Json выхода?