Solved

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

Posted on 2016-08-02
10
43 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
ID: 41738769
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
ID: 41738828
If you're manipulating this data programatically, you should probably be using a bean
0
 
LVL 15

Expert Comment

by:gurpsbassi
ID: 41738952
as CEHJ said, use a JSON library
0
 
LVL 1

Author Comment

by:srikotesh
ID: 41739539
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
ID: 41739848
Use Jackson to serialise it.
Add annotations for jsonroot and property annotations to getters.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 15

Expert Comment

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

Author Comment

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

Expert Comment

by:gurpsbassi
ID: 41747050
That's a bad choice.
0
 
LVL 1

Author Comment

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

Expert Comment

by:gurpsbassi
ID: 41747112
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 79
Need to track down Infection in a Server 2008 domain user profile 7 48
eclipse shortcuts 9 45
Error trying to install RTMT Win7 5 41
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

920 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

14 Experts available now in Live!

Get 1:1 Help Now