#442 - @JsonIgnore / @Expose ... not working on @OneToMany or @ManyToMany - was - @Transient field on @MappedSuperclass is not ignored by toJson()

This commit is contained in:
Robin Bygrave
2015-10-28 09:10:19 +13:00
parent 3d62f58930
commit 67c711d75f
4 changed files with 47 additions and 27 deletions
@@ -1,11 +1,15 @@
package com.avaje.tests.iud;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.tests.model.info.InfoCompany;
import com.avaje.tests.model.info.InfoCustomer;
import org.junit.Assert;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
public class TestInfoOneToOne extends BaseTestCase {
@Test
@@ -20,13 +24,17 @@ public class TestInfoOneToOne extends BaseTestCase {
customer.save();
// assert JsonIgnore working as expected
String asJson = Ebean.json().toJson(company);
assertThat(asJson).doesNotContain("contacts");
// assert both are inserted
Assert.assertNotNull(customer.getId());
Assert.assertNotNull(company.getId());
assertNotNull(customer.getId());
assertNotNull(company.getId());
// both can be fetched
Assert.assertNotNull(InfoCustomer.find.byId(customer.getId()));
Assert.assertNotNull(InfoCompany.find.byId(company.getId()));
assertNotNull(InfoCustomer.find.byId(customer.getId()));
assertNotNull(InfoCompany.find.byId(company.getId()));
// just update the customer
@@ -47,8 +55,8 @@ public class TestInfoOneToOne extends BaseTestCase {
// delete both customer and company
fetchedCustomer.delete();
Assert.assertNull(InfoCustomer.find.byId(customer.getId()));
Assert.assertNull(InfoCompany.find.byId(company.getId()));
assertNull(InfoCustomer.find.byId(customer.getId()));
assertNull(InfoCompany.find.byId(company.getId()));
}
@@ -1,6 +1,7 @@
package com.avaje.tests.model.info;
import com.avaje.ebean.Model;
import com.avaje.ebean.annotation.JsonIgnore;
import javax.persistence.*;
import java.util.ArrayList;
@@ -19,6 +20,7 @@ public class InfoCompany extends Model {
String name;
@JsonIgnore
@OneToMany(mappedBy = "company", cascade = CascadeType.ALL)
List<InfoContact> contacts = new ArrayList<InfoContact>();
@@ -2,7 +2,11 @@ package com.avaje.tests.model.info;
import com.avaje.ebean.Model;
import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Version;
@Entity
public class InfoCustomer extends Model {