Avatar of srikotesh
srikotesh
 asked on

how to store String(json formatted String) value to a list

I am getting the below val as a string from DB
I want to add this values to a list
contactname,and contactmobile as one object we need to insert in list.

input:
{"contactName":"Girish Prabhu","contactMobile":"9952670691"},{"contactName":"Gopal Prasad","contactMobile":"9123560000"}


Expected output:

groupContacts:
            [
                {
                    "contactName": "Girish Prabhu",
                    "contactMobile": "9952670691"
                },{
                    "contactName": "Gopal Prasad",
                    "contactMobile": "9123560000"
                }
            ]
JavaJSONJava EE

Avatar of undefined
Last Comment
gurpsbassi

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CEHJ

If you're manipulating this data programatically, you should probably be using a bean
gurpsbassi

as CEHJ said, use a JSON library
srikotesh

ASKER
Thanks Ryan chong,

Hi CEHJ,

how can i get this string value using json.

I have create bean
public class ContactInfo {
	private List<Contact> contacts;
}

public class Contact {
	private String contactName;
	private String contactNo;
}

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
gurpsbassi

Use Jackson to serialise it.
Add annotations for jsonroot and property annotations to getters.
gurpsbassi

Unbelievable. Your going to use string manipulation  instead?
srikotesh

ASKER
I don't know about Jackson serialization. so I prefer to go with that approach only
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
gurpsbassi

That's a bad choice.
srikotesh

ASKER
I don't know about Jackson serialization
and how to get the string val from it.
gurpsbassi

Read up about it if you want to do it right.
Jackson is not the only option . There's others such as gson.

Being a developer means you should seek the best solutions that will be easy to maintain in future. Dont take shortcuts just because you can't be bothered to put the effort in.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck