Skip to content

Commit

Permalink
Merge pull request #5421 from the-bug/master
Browse files Browse the repository at this point in the history
*persistant*-attribute of a panache entity should not be generated when using jackson
  • Loading branch information
FroMage authored Nov 20, 2019
2 parents dd86525 + 07aeae2 commit 92669f2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions extensions/panache/hibernate-orm-panache/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<artifactId>jakarta.json.bind-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import javax.persistence.LockModeType;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.quarkus.hibernate.orm.panache.runtime.JpaOperations;
import io.quarkus.panache.common.Parameters;
import io.quarkus.panache.common.Sort;
Expand Down Expand Up @@ -75,6 +77,8 @@ public void delete() {
* @return true if this entity is persistent in the database.
*/
@JsonbTransient
// @JsonIgnore is here to avoid serialization of this property with jackson
@JsonIgnore
public boolean isPersistent() {
return JpaOperations.isPersistent(this);
}
Expand Down
5 changes: 5 additions & 0 deletions integration-tests/hibernate-orm-panache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<artifactId>quarkus-test-h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package io.quarkus.it.panache;

import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.quarkus.test.junit.DisabledOnNativeImage;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
Expand Down Expand Up @@ -49,4 +53,23 @@ public void testPanacheInTest() {
public void testBug5274() {
RestAssured.when().get("/test/5274").then().body(is("OK"));
}

/**
* This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint.
*/
@DisabledOnNativeImage
@Test
public void jacksonDeserilazationIgnoresPersitantAttribute() throws JsonProcessingException {
// set Up
Person person = new Person();
person.name = "max";
// do
ObjectMapper objectMapper = new ObjectMapper();
String personAsString = objectMapper.writeValueAsString(person);
// check
// hence no 'persistence'-attribute
assertEquals(
"{\"id\":null,\"name\":\"max\",\"uniqueName\":null,\"address\":null,\"status\":null,\"dogs\":[],\"serialisationTrick\":1}",
personAsString);
}
}

0 comments on commit 92669f2

Please sign in to comment.