I have an request object, that contains a huge amount of data. But there is a filter in my code, where I need to take out just one element. At the moment I am Deserializing the whole object, which seems overkill to just get one element
This is part of a zuul filter
import com.netflix.zuul.context.RequestContext;
RequestContext ct = RequestContext.getCurrentContext(); HttpServletRequest request = ctx.getRequest(); ObjectMapper mapper = new ObjectMapper(); ServletInputStream stream = null; try { stream = request.getInputStream(); GetPageRequest page = mapper.readValue(stream,GetPageRequest.class); log.info("URL IN BODY "+page.getUrl());
It seems over kill to deserialize an entire object to get one element but I cant think of a more efficient and optomized way
Advertisement
Answer
At it’s simplest the request payload can just be a string so you could read the input as a string and then parse what you want out using a regular expression or an indexOf
or whatever suits best?