How to read JSON request body in Jersey

前端 未结 2 422
广开言路
广开言路 2021-02-08 10:41

I have a requirement, where in i need to read JSON request that is coming in as part of the request and also convert it to POJO at the same time. I was able to convert it to POJ

2条回答
  •  甜味超标
    2021-02-08 11:21

    One posibility is to use a ContainerRequestFilter that's called before your method is invoked:

    public class MyRequestFilter 
      implements ContainerRequestFilter {
            @Override
        public ContainerRequest filter(ContainerRequest req) {
                // ... get the JSON payload here
                return req;
            }
    }
    

提交回复
热议问题