如何使用Jackson /其他库将json响应对象映射到首选格式?(How to map json response object to a preferred format using Jackson / other library?)
我从第三方Web服务获得以下JSON响应格式:
{ "meta": { "code": 200, "requestId": "1" }, "response": { "locations": [ { "id": "1", "name": "XXX", "contact": { phone: '123', email: 'abc' }, "location": { "address": [ "Finland" ] } }, { // another location } ] } }
以下是我应该从我自己的Web服务返回的内容:
[ { "id": "1", "name": "XXX", "phone": '123', "address": "Finland" }, { // another location } ]
我该怎么办? 我已经阅读了一些关于杰克逊的好东西,但是只有几个简单的例子,你将一些简单的JSON obj映射到POJO。 在我的例子中,我需要删除一些节点,并在层次结构中更深入地遍历以获取嵌套值。 到目前为止,这是我的春季启动应用中的宝贝步骤:
@GET @Path("{query}") @Produces("application/json") public String getVenues(@PathParam("query") String query){ return client.target(url).queryParam("query",query).request(...).get(String.class) }
任何帮助,指针,建议都欢迎!
I am getting the below JSON response format from a third party web service:
{ "meta": { "code": 200, "requestId": "1" }, "response": { "locations": [ { "id": "1", "name": "XXX", "contact": { phone: '123', email: 'abc' }, "location": { "address": [ "Finland" ] } }, { // another location } ] } }
And here is what I should return as a response from my own web service:
[ { "id": "1", "name": "XXX", "phone": '123', "address": "Finland" }, { // another location } ]
What should I do? I've read some good stuff about Jackson but there are only a few simple examples where you map some simple JSON obj as is to POJO. In my case, I need to remove a few nodes, and also traverse deeper down the hierarchy to get the nested value. This is my baby step so far in my spring boot app:
@GET @Path("{query}") @Produces("application/json") public String getVenues(@PathParam("query") String query){ return client.target(url).queryParam("query",query).request(...).get(String.class) }
Any helps, pointers, recommendations are welcomed!
原文:https://stackoverflow.com/questions/35191510
最满意答案
我把你的代码弹出一个编辑器来试一试。
我想你想要根据你的需要做一些改变。
nav ul li ul { display: none; } nav ul li:hover > ul { display:block; position:absolute; top: 100%; left: 0; } nav ul li { position: relative; }
这将使下拉显示在正确的位置。 他们仍然需要造型但
position:absolute
与相对容器阻止他们影响周围的布局,我相信你想要的。希望能帮到你!
注意::您可以看到更改如何影响以下代码段。
nav ul li ul { display: none;} nav ul li:hover > ul { display:block; position:absolute; top: 100%; left: 0; } nav ul li { position: relative; }
<html> <head> <meta charset="UTF-8"> <title></title> <link href="../CSS/Main.css" rel="stylesheet" type="text/css"> </head> <body background="../backgroundImage/UtahMoutains-copy7.png"style="background-repeat:no-repeat; background-position:center; background-attachment:fixed; background-size:cover; margin:0px;"> <div style=" float:left; width:100%; background-color:#DDD margin:0; position:relative; margin:0px;"> <img src="../backgroundImage/utahGovLogo.png" style=" float:left; padding:20px;"> <img src="../Images/Search Button.png" style="float:right; padding:20px;"> </div> <nav> <ul style="list-style:none; text-align:center; background-color:#DDD; font-family: Arial,Helvetica, Neue,sans-serif; font-size:120%; color:#666; margin:0px;"> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#" style=""> Government </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">State Agencies</a></li> <li><a href="#" style="">Governors Office</a></li> <li><a href="#" style="">Executive Branch</a></li> <li><a href="#" style="">Legislative Branch</a></li> <li><a href="#" style="">Judicial Branch</a></li> <li><a href="#" style="">City & County Government</a></li> <li><a href="#" style="">Federal Government</a></li> <li><a href="#" style="">Election & Voting</a></li> <li><a href="#" style="">Utah Code & Constitution</a></li> <li><a href="#" style="">State Telephone Directory</a></li> <li><a href="#" style="">Utah Data</a></li> <li><a href="#" style="">Open.Utah.gov</a></li> </ul><!-- end of Government drop down menu--> </li><!-- end of Government Button--> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Services </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Utah.gov Online Services</a></li> <li><a href="#" style="">Citizen Services</a></li> <li><a href="#" style="">Business Services</a></li> <li><a href="#" style="">Gov to Gov Services</a></li> <li><a href="#" style="">Financial</a></li> <li><a href="#" style="">Legal</a></li> <li><a href="#" style="">Utah.gov Registration</a></li> <li><a href="#" style="">Citizen Alerts</a></li> <li><a href="#" style="">Trending</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Employment </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Find a Job</a></li> <li><a href="#" style="">Education & Training</a></li> <li><a href="#" style="">State Employment</a></li> <li><a href="#" style="">Careers</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Business </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Online Business Serices</a></li> <li><a href="#" style="">Starting a Business</a></li> <li><a href="#" style="">Running a Business</a></li> <li><a href="#" style="">Relocating a Business</a></li> <li><a href="#" style="">Dissolving a Business</a></li> <li><a href="#" style="">Assess your Business Idea</a></li> <li><a href="#" style="">Select your Business Structure</a></li> <li><a href="#" style="">Prepare a Written Business Plan</a></li> <li><a href="#" style="">Government Business Requirments</a></li> <li><a href="#" style="">Financial Resources</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Education </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">K - 12 Education</a></li> <li><a href="#" style="">Colleges & Universities</a></li> <li><a href="#" style="">Educational Resources</a></li> <li><a href="#" style="">STEM</a></li> <li><a href="#" style="">Utah History for Kids</a></li> <li><a href="#" style="">Homework Help</a></li> <li><a href="#" style="">Libraries</a></li> <li><a href="#" style="">Student Network</a></li> <li><a href="#" style="">School Reports</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Resident </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Citizens & Community</a></li> <li><a href="#" style="">Health & Social Serives</a></li> <li><a href="#" style="">Newcomers Guide</a></li> <li><a href="#" style="">Moving to Utah</a></li> <li><a href="#" style="">Cars & Transportation</a></li> <li><a href="#" style="">Utah Laws</a></li> <li><a href="#" style="">Tax Information</a></li> <li><a href="#" style="">RSS ( Just for Youth)</a></li> <li><a href="#" style="">Seniors.Utah.gov</a></li> <li><a href="#" style="">Help your Neighbor</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Visiting </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Travel & Tourism</a></li> <li><a href="#" style="">State Parks</a></li> <li><a href="#" style="">Arts & Culture</a></li> <li><a href="#" style="">Highway Information</a></li> <li><a href="#" style="">Sports & Recreation</a></li> <li><a href="#" style="">Arts & Leisure</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> About </a> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Connect </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Facebook</a></li> <li><a href="#" style="">Twitter</a></li> <li><a href="#" style="">Google +</a></li> <li><a href="#" style="">Photos</a></li> <li><a href="#" style="">YouTube</a></li> <li><a href="#" style="">Mobile</a></li> </ul> </li> </ul> </nav>
I popped your code into an editor to give it a go.
I think you're looking to make slight changes for what you need.
nav ul li ul { display: none; } nav ul li:hover > ul { display:block; position:absolute; top: 100%; left: 0; } nav ul li { position: relative; }
This will make the drop downs appear in the right position. They will still need styling but
position:absolute
with a relative container stops them from affecting the surrounding layout which is I believe what you desire.Hope that helps you out!
NOTE:: You can see how the changes affect with the following snippet.
nav ul li ul { display: none;} nav ul li:hover > ul { display:block; position:absolute; top: 100%; left: 0; } nav ul li { position: relative; }
<html> <head> <meta charset="UTF-8"> <title></title> <link href="../CSS/Main.css" rel="stylesheet" type="text/css"> </head> <body background="../backgroundImage/UtahMoutains-copy7.png"style="background-repeat:no-repeat; background-position:center; background-attachment:fixed; background-size:cover; margin:0px;"> <div style=" float:left; width:100%; background-color:#DDD margin:0; position:relative; margin:0px;"> <img src="../backgroundImage/utahGovLogo.png" style=" float:left; padding:20px;"> <img src="../Images/Search Button.png" style="float:right; padding:20px;"> </div> <nav> <ul style="list-style:none; text-align:center; background-color:#DDD; font-family: Arial,Helvetica, Neue,sans-serif; font-size:120%; color:#666; margin:0px;"> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#" style=""> Government </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">State Agencies</a></li> <li><a href="#" style="">Governors Office</a></li> <li><a href="#" style="">Executive Branch</a></li> <li><a href="#" style="">Legislative Branch</a></li> <li><a href="#" style="">Judicial Branch</a></li> <li><a href="#" style="">City & County Government</a></li> <li><a href="#" style="">Federal Government</a></li> <li><a href="#" style="">Election & Voting</a></li> <li><a href="#" style="">Utah Code & Constitution</a></li> <li><a href="#" style="">State Telephone Directory</a></li> <li><a href="#" style="">Utah Data</a></li> <li><a href="#" style="">Open.Utah.gov</a></li> </ul><!-- end of Government drop down menu--> </li><!-- end of Government Button--> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Services </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Utah.gov Online Services</a></li> <li><a href="#" style="">Citizen Services</a></li> <li><a href="#" style="">Business Services</a></li> <li><a href="#" style="">Gov to Gov Services</a></li> <li><a href="#" style="">Financial</a></li> <li><a href="#" style="">Legal</a></li> <li><a href="#" style="">Utah.gov Registration</a></li> <li><a href="#" style="">Citizen Alerts</a></li> <li><a href="#" style="">Trending</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Employment </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Find a Job</a></li> <li><a href="#" style="">Education & Training</a></li> <li><a href="#" style="">State Employment</a></li> <li><a href="#" style="">Careers</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Business </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Online Business Serices</a></li> <li><a href="#" style="">Starting a Business</a></li> <li><a href="#" style="">Running a Business</a></li> <li><a href="#" style="">Relocating a Business</a></li> <li><a href="#" style="">Dissolving a Business</a></li> <li><a href="#" style="">Assess your Business Idea</a></li> <li><a href="#" style="">Select your Business Structure</a></li> <li><a href="#" style="">Prepare a Written Business Plan</a></li> <li><a href="#" style="">Government Business Requirments</a></li> <li><a href="#" style="">Financial Resources</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Education </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">K - 12 Education</a></li> <li><a href="#" style="">Colleges & Universities</a></li> <li><a href="#" style="">Educational Resources</a></li> <li><a href="#" style="">STEM</a></li> <li><a href="#" style="">Utah History for Kids</a></li> <li><a href="#" style="">Homework Help</a></li> <li><a href="#" style="">Libraries</a></li> <li><a href="#" style="">Student Network</a></li> <li><a href="#" style="">School Reports</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Resident </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Citizens & Community</a></li> <li><a href="#" style="">Health & Social Serives</a></li> <li><a href="#" style="">Newcomers Guide</a></li> <li><a href="#" style="">Moving to Utah</a></li> <li><a href="#" style="">Cars & Transportation</a></li> <li><a href="#" style="">Utah Laws</a></li> <li><a href="#" style="">Tax Information</a></li> <li><a href="#" style="">RSS ( Just for Youth)</a></li> <li><a href="#" style="">Seniors.Utah.gov</a></li> <li><a href="#" style="">Help your Neighbor</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Visiting </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Travel & Tourism</a></li> <li><a href="#" style="">State Parks</a></li> <li><a href="#" style="">Arts & Culture</a></li> <li><a href="#" style="">Highway Information</a></li> <li><a href="#" style="">Sports & Recreation</a></li> <li><a href="#" style="">Arts & Leisure</a></li> </ul> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> About </a> </li> <li style="display: inline-block; margin-top:20px; margin-left:2%; margin-right:2%; margin-bottom:10px;"><a href="#"> Connect </a> <ul style="text-decoration:none; list-style:none;"> <li><a href="#" style="">Facebook</a></li> <li><a href="#" style="">Twitter</a></li> <li><a href="#" style="">Google +</a></li> <li><a href="#" style="">Photos</a></li> <li><a href="#" style="">YouTube</a></li> <li><a href="#" style="">Mobile</a></li> </ul> </li> </ul> </nav>
相关问答
更多-
CSS Bootstrap下拉菜单(CSS Bootstrap Dropdown Menu)[2022-05-06]
你错放了CSS课程 应该只有一个.dropdown-menu,它包含所有.dropdown-menu-item元素Bootstrap Menu Ex。 belowe