How to convert MultiMap into json format in VERTX

2,482 views
Skip to first unread message

Yogesh Kumar

unread,
Nov 8, 2016, 2:00:21 AM11/8/16
to vert.x


Hi All,

I am passing data as form (ie key and value pair),then getting this data as a MultiMap object.


MultiMap clientMap = routingContext.request().formAttributes();


Client Map Value :

firstName: Raj
lastName: ku
address1: bang
city: bhiwani
state: Alabama
zip: 22222
country: US
shippingMethod: 1a



Requirement : need to convert this map (clientMap) into json format like given below.


{"firstName":"RAVI","lastName":"Mandli","address1":"Hno22","Company":"Sapient","address2":"CityRoad","city":"Surat","state":"Gujrat","zip":"127040","country":"India","saveToAccount":"true","shippingMethod":"1a"}


tried too much way but not getting any solutions. Please give appropriate solutions.


Thanks ,
Yogesh Kumar




aa.png

Thomas SEGISMONT

unread,
Nov 8, 2016, 4:53:57 AM11/8/16
to ve...@googlegroups.com
Multimap is an Iterable of Map.Entry<String, String>. So it should be easy to loop over those entries and build a JsonObject instance.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/0043a5da-7fed-4115-b3f5-2cc16199b75e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jez P

unread,
Nov 8, 2016, 6:18:29 AM11/8/16
to vert.x
As Thomas said, it should be straightforward. Could you please explain what the problem is you're running into. Maybe post something you've tried so we can suggest more direct refinements to something you've already done.


On Tuesday, November 8, 2016 at 9:53:57 AM UTC, Thomas Segismont wrote:
Multimap is an Iterable of Map.Entry<String, String>. So it should be easy to loop over those entries and build a JsonObject instance.
2016-11-08 8:00 GMT+01:00 Yogesh Kumar <yogesh...@gmail.com>:


Hi All,

I am passing data as form (ie key and value pair),then getting this data as a MultiMap object.


MultiMap clientMap = routingContext.request().formAttributes();


Client Map Value :

firstName: Raj
lastName: ku
address1: bang
city: bhiwani
state: Alabama
zip: 22222
country: US
shippingMethod: 1a



Requirement : need to convert this map (clientMap) into json format like given below.


{"firstName":"RAVI","lastName":"Mandli","address1":"Hno22","Company":"Sapient","address2":"CityRoad","city":"Surat","state":"Gujrat","zip":"127040","country":"India","saveToAccount":"true","shippingMethod":"1a"}


tried too much way but not getting any solutions. Please give appropriate solutions.


Thanks ,
Yogesh Kumar




--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Jez P

unread,
Nov 8, 2016, 6:23:53 AM11/8/16
to vert.x
Or you could iterate over the list of string returned by the names() method, check the size of the list of entries returned, if just one add it as a string to the parent JsonObject, if multiple then add a json array object and add each member individually. Neither approach seems complex to me (mine might be easier to implement if you expect multiple entries for a given name, Thomas' more straightforward if you know you only get one entry per name). 

On Tuesday, November 8, 2016 at 9:53:57 AM UTC, Thomas Segismont wrote:
Multimap is an Iterable of Map.Entry<String, String>. So it should be easy to loop over those entries and build a JsonObject instance.
2016-11-08 8:00 GMT+01:00 Yogesh Kumar <yogesh...@gmail.com>:


Hi All,

I am passing data as form (ie key and value pair),then getting this data as a MultiMap object.


MultiMap clientMap = routingContext.request().formAttributes();


Client Map Value :

firstName: Raj
lastName: ku
address1: bang
city: bhiwani
state: Alabama
zip: 22222
country: US
shippingMethod: 1a



Requirement : need to convert this map (clientMap) into json format like given below.


{"firstName":"RAVI","lastName":"Mandli","address1":"Hno22","Company":"Sapient","address2":"CityRoad","city":"Surat","state":"Gujrat","zip":"127040","country":"India","saveToAccount":"true","shippingMethod":"1a"}


tried too much way but not getting any solutions. Please give appropriate solutions.


Thanks ,
Yogesh Kumar




--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Yogesh Kumar

unread,
Nov 8, 2016, 6:46:27 AM11/8/16
to vert.x
Thanks a lot ... this is a good solution.

JsonObject metadata = new JsonObject();
for (Map.Entry<String, String> entry : dataMap.entries()) {
metadata.put(entry.getKey(), entry.getValue());
}

done it same way and problem resolved .

Thanks again :)
Reply all
Reply to author
Forward
0 new messages