Solved

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

Posted on 2016-08-02
10
39 Views
Last Modified: 2016-08-08
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"
                }
            ]
0
Comment
Question by:srikotesh
10 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
since it's a string, why not just add in the front end back like this?
String newstring =  "groupContacts: [" + yourInpuy + "]";

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
If you're manipulating this data programatically, you should probably be using a bean
0
 
LVL 15

Expert Comment

by:gurpsbassi
Comment Utility
as CEHJ said, use a JSON library
0
 
LVL 1

Author Comment

by:srikotesh
Comment Utility
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

0
 
LVL 15

Expert Comment

by:gurpsbassi
Comment Utility
Use Jackson to serialise it.
Add annotations for jsonroot and property annotations to getters.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 15

Expert Comment

by:gurpsbassi
Comment Utility
Unbelievable. Your going to use string manipulation  instead?
0
 
LVL 1

Author Comment

by:srikotesh
Comment Utility
I don't know about Jackson serialization. so I prefer to go with that approach only
0
 
LVL 15

Expert Comment

by:gurpsbassi
Comment Utility
That's a bad choice.
0
 
LVL 1

Author Comment

by:srikotesh
Comment Utility
I don't know about Jackson serialization
and how to get the string val from it.
0
 
LVL 15

Expert Comment

by:gurpsbassi
Comment Utility
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.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now