I want to convert a string to json list. I am currently working on a web api using spring boot. There is a table which contains multiple value at a ssingle column and similarly all the columns are having multi values. Like: There is a car company. There is a column named models - which contains more than one models and then there there is a price column which contains all the models price respectively. Now I have to convert those strings to json format.
I tried using the split()
in java for that but that is giving the address location as output.
Model class
..........//getters and setters and declarations
@Override
public String toString() {
String ar = car_type;
String ar1[]=ar.split(",");
int l = ar1.length;
return "{" +
"\"car_comp\":" +"\"" + car_comp+ "\""+"," +
"\"car_type\":" +"\""+ ar1 + "\""+","+
"\"car_price\":" +"\""+ car_price+ "\""+","+
"\"car_comp_value\":"+"\"" + car_comp_value +"\""+
'}';
}
I used the length function to check whether the array is being created of the right size or not.
The Output
"car_comp": {
"car_comp": "bmw",
"car_type": "[Ljava.lang.String;@4017b770",
"car_price": "$1500",
"car_comp_value": "$65.4M"
}
PLEASE IGNORE THE DATA.. But the car type is showing not what I expected. To be honest this is my first time working in web api and json and I don't have much idea how to do things with it. The Expected Output :
"car_comp": {
"car_comp": "bmw",
"car_type": [{modelA},{modelB},{modelC}],
"hb_unit_hints": "Kg",
"hb_value": "65.4"
}
Thanks in Advance.