jersey
  1. jersey
  2. JERSEY-2286

entity-filter does not work if entity is changed by interceptor or filter

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.4.1
    • Fix Version/s: None
    • Component/s: extensions
    • Labels:
      None
    • Environment:

      tomcat 7

      Description

      I have a interceptor change the entity to add common wrapper to the returned entity from method call.

      @Override
      	public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
      		Object entity = context.getEntity();
                      
                      //this class provide general information such as timestamp, user, status, etc.
      		RSRet ret = new RSRet();
      		if (entity instanceof RSRet || entity instanceof String) {
      			context.proceed();
      			return;
      		}
      		if (entity != null) {
      			if (entity.getClass().isArray()) {
      				ret.setList((Object[]) entity);
      			} else if (List.class.isAssignableFrom(entity.getClass())) {
      				List l = (List) entity;
      				ret.setList(l.toArray());
      			} else {
      				ret.setData(entity);
      			}
      		}
      		context.setEntity(ret);
      		context.proceed();
      
      	}
      

      The built object graph does not go through this object. I always get {} in http response

        Activity

        Hide
        Miroslav Fuksa added a comment -

        Hi,

        I do not understand what the problem is. I understand your interceptor but I don't know what you want do you mean that "The built object graph does not go through this object. I always get {} in http response". What do you mean by entity-filter in the bug title?

        ContainerResponseFilter is executed before WriterInterceptor. This is the design defined by JAX-RS 2.0. Is this what you mean? You would like to execute filter after the interceptor?

        thanks
        Mira

        Show
        Miroslav Fuksa added a comment - Hi, I do not understand what the problem is. I understand your interceptor but I don't know what you want do you mean that "The built object graph does not go through this object. I always get {} in http response". What do you mean by entity-filter in the bug title? ContainerResponseFilter is executed before WriterInterceptor. This is the design defined by JAX-RS 2.0. Is this what you mean? You would like to execute filter after the interceptor? thanks Mira
        Hide
        Michal Gajdos added a comment -

        Seems like you're changing the entity that is later on marshalled to JSON. How does the annotations on this entity look like?

        Show
        Michal Gajdos added a comment - Seems like you're changing the entity that is later on marshalled to JSON. How does the annotations on this entity look like?
        Hide
        Marek Potociar added a comment -

        This improvement has not collected any support votes and has not been updated this year at all. Closing as won't fix due to not enough interest from the community.

        Show
        Marek Potociar added a comment - This improvement has not collected any support votes and has not been updated this year at all. Closing as won't fix due to not enough interest from the community.

          People

          • Assignee:
            Unassigned
            Reporter:
            jasonzhang2002gmailcom
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: