json-view icon indicating copy to clipboard operation
json-view copied to clipboard

Spring usage is not excluding Object field

Open dhoffer opened this issue 9 years ago • 0 comments

I'm using this in a Spring (Boot) application so have followed the instructions to create the JsonViewSupportFactoryBean Bean however its not excluding the excluded entity field at all. The excluded field is a reference to another domain entity.

Here is the entity:

`public class Attitudestate implements java.io.Serializable, UniquelyIdentified<Long> { private Long id; private Runcatalog runidentity; private Integer runidentityId; private Double gpstime; private Date utctimestamp; private transient Double[] attitude; private Float attitudeerror; private Float currentangularrate; private Float angularrateerror;

@JoinColumn(name = "runidentity", nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
@XmlTransient
public Runcatalog getRunidentity()
{
    return this.runidentity;
}

public void setRunidentity(Runcatalog runidentity)
{
    this.runidentity = runidentity;
}`

In my controller I have:

`private JsonResult json = JsonResult.instance();

public Page<Attitudestate> findByRunIdentityId(Integer runidentityId, Pageable pageable) { Page<Attitudestate> attitudestates = repository.findByRunIdentityId(runidentityId, pageable);

    return json.use(JsonView.with(attitudestates)
        .onClass(Attitudestate.class, Match.match()
            .exclude("runidentity")))
        .returnValue();
}`

However the resulting REST response has the runidentity instance which by the way contains a reference to Attitudestate. I want to simply ignore runidentity in the REST response as it already has runidentityId. I can do this with which I can do with @JsonIgnore in the entity but I would prefer to not change my entities.

dhoffer avatar Dec 30 '16 20:12 dhoffer