Yeshvanthni
Yeshvanthni

Reputation: 207

Getting JsonIgnore or JsonIgnoreProperties to work on servlet filter

The Java object has to be serialized into a json string in the servlet filter for a jersey application.

Have the following object,

 @XmlRootElement
 @JsonIgnoreProperties({"bar"})
 public class Foo{
    String a="1";

    String b="2";

    @JsonIgnore
    String bar="3";

    };



      ObjectMapper om = new ObjectMapper();
      om.writeValueAsString(fooObject);

returns,

        {
          a:"1",
          b:"2",
          bar:"3" // Inspite of Jsonignore and jsonignoreproperties bar is returned
          }

How do I overcome this?

Upvotes: 0

Views: 2271

Answers (2)

Yeshvanthni
Yeshvanthni

Reputation: 207

Fixing the imports to fasterxml from codehaus and adding the following feature to the mapper fixed the issue.

      mapper.configure(MapperFeature.USE_ANNOTATIONS, true);

Upvotes: 1

secondflying
secondflying

Reputation: 871

use @XmlTransient:

@XmlTransient
String bar="3";

Upvotes: 0

Related Questions