-1

I am trying to make it so these properties don't get serialized, but for some reason no matter what I do they are still getting serialized and sent down to the client. I have tried using just @JsonIgnoreProperties({"doBefore","doAfter","doAfterComplete"}), I have tried using just @JsonIgnore on the getters, and I have tried both together and it doesn't seem to make a difference. Here's what my class looks like:

@JsonIgnoreProperties({"doBefore","doAfter","doAfterComplete"})
public class Action
{
    //for reordering actions with the default actions
    private String doBefore;
    private String doAfter;
    private String doAfterComplete;

    private String eventId;
    private List<ActionArgument> arguments;
    //action to perform when this action is done
    private List<Action> onCompleteActions;

    public Action() {}

    public Action(String eventId, List<ActionArgument> arguments, List<Action> onCompleteActions)
    {
        this.eventId = eventId;
        this.arguments = arguments;
        this.onCompleteActions = onCompleteActions;
    }

    public String getEventId()
    {
        return eventId;
    }
    public void setEventId(String eventId)
    {
        this.eventId = eventId;
    }
    public List<ActionArgument> getArguments()
    {
        return arguments;
    }
    public void setArguments(List<ActionArgument> arguments)
    {
        this.arguments = arguments;
    }
    public List<Action> getOnCompleteActions()
    {
        return onCompleteActions;
    }
    public void setOnCompleteActions(List<Action> onCompleteActions)
    {
        this.onCompleteActions = onCompleteActions;
    }

    @JsonIgnore public String getDoBefore()
    {
        return doBefore;
    }

    public void setDoBefore(String doBefore)
    {
        this.doBefore = doBefore;
    }

    @JsonIgnore public String getDoAfter()
    {
        return doAfter;
    }

    public void setDoAfter(String doAfter)
    {
        this.doAfter = doAfter;
    }

    @JsonIgnore public String getDoAfterComplete()
    {
        return doAfterComplete;
    }

    public void setDoAfterComplete(String doAfterComplete)
    {
        this.doAfterComplete = doAfterComplete;
    }
}
jensengar
  • 6,117
  • 17
  • 58
  • 90

1 Answers1

1

You can use @JsonIgnore on each getter and setter. I like this as it seems easier to see which ones are ignored. Plus you can have a property ignored for serialization and not ignored for deserialization. (That does assume the remote client isn't using the same code, doesn't it.)

It works for me with Jersey/Jackson. What jaxrs framework are you using?

For Jersey, you also need a section in your web.xml file:

<servlet>
    <servlet-name>MyJaxRSServlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.mycompany.transformation</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

This is where you tell it to scan packages com.mycompany.transformation.** for the annotations.

Lee Meador
  • 12,829
  • 2
  • 36
  • 42