如何在spring restful服务中响应json时附加一些字符串

时间:2016-07-13 10:16:53

标签: spring jackson

这是代码:

@RequestMapping(value="/find/city={city}", method=RequestMethod.GET)
public String getCity(@PathVariable String city) throws JsonParseException, IOException 
{
    ObjectMapper mapper = new ObjectMapper();
    SimpleBeanPropertyFilter theFilter = SimpleBeanPropertyFilter.serializeAllExcept("id","miscellaneous","country","foundin","code","latlong","state");
    FilterProvider filters = new SimpleFilterProvider().addFilter("myFilter", theFilter);

    return mapper.writer(filters).writeValueAsString(City_Repository.findByCityLikeIgnoreCase(city));
     }

作出回应:

[
  {
    "indexid": 65,
    "city": "Barcelona"
  },
  {
    "indexid": 158,
    "city": "Dillons Bay"
  },
  {
    "indexid": 232,
    "city": "East London"
  }]

我在回复中是必需的:

[ 
    {
        type: "airport", 
        "airport": { "indexid": 65, "city": "Barcelona" }, 
                   { "indexid": 158, "city": "Dillons Bay" }, 
                   { "indexid": 232, "city": "East London" }
]

0 个答案:

没有答案