我在Java Rest API中使用Jackson来处理请求参数。
我的Bean类:
public class ZoneModifBeanParam extends ModifBeanParam<Zone> {
@FormParam("type")
private String type;
@FormParam("geometry")
private Geometry geometry;
@FormParam("name")
private String name;
...
我的API接口:
@POST
@Consumes("application/json")
@Produces("application/json; subtype=geojson")
@ApiOperation(value = "Create a zone", notes = "To create a zone")
public Response createZone(ZoneModifBeanParam zoneParam) {
...
这个可以正常工作,但我需要在一个Map中接收一些没有在我的Bean中指定的其他参数。 例如:
{
"geometry": {...},
"name": "A circle name",
"type": "4",
"hello": true
}
接收到这个之后,我需要将“hello”和true作为一对键值存储在我的bean中声明的Map(名为unrecognizedFields)中。
是否有任何注解或对象可以实现这个功能?
ObjectMapper
来安全地忽略未识别的字段,但是如果要将它们作为键值对放入Map
字段中,则需要自己编写反序列化器。 - Mena