forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Honour @JsonIgnore on Panache entities
Fixes: quarkusio#10339
- Loading branch information
Showing
5 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.it.panache; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase; | ||
|
||
@Entity | ||
public class Book extends PanacheEntityBase { | ||
|
||
@Id | ||
@GeneratedValue | ||
public Integer id; | ||
|
||
public String name; | ||
|
||
@JsonIgnore | ||
public String author; | ||
|
||
public Book(String name, String author) { | ||
this.name = name; | ||
this.author = author; | ||
} | ||
|
||
public Book() { | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/BookDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.it.panache; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; | ||
|
||
@ApplicationScoped | ||
public class BookDao implements PanacheRepositoryBase<Book, Integer> { | ||
} |
27 changes: 27 additions & 0 deletions
27
...gration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/BookResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.it.panache; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.transaction.Transactional; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path("/book") | ||
public class BookResource { | ||
|
||
@Inject | ||
BookDao bookDao; | ||
|
||
@Transactional | ||
@GET | ||
@Path("/{name}/{author}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public List<Book> addAndListAll(@PathParam("name") String name, @PathParam("author") String author) { | ||
bookDao.persist(new Book(name, author)); | ||
return bookDao.listAll(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/JacksonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.it.panache; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
public class JacksonTest { | ||
|
||
@Test | ||
public void testJsonIgnoreHonoured() { | ||
List<Book> books = RestAssured.when().get("/book/Berlin/Beevor").then().extract().body().jsonPath().getList(".", | ||
Book.class); | ||
assertThat(books).hasSize(1).filteredOn(book -> book.author != null).isEmpty(); | ||
} | ||
} |