Skip to content

Commit 74c3a56

Browse files
committed
Include JSONB example in hibernate quickstart
Example to clarify Quarkus issue # 36730
1 parent 6af12d5 commit 74c3a56

File tree

2 files changed

+37
-0
lines changed
  • hibernate-orm-rest-data-panache-quickstart/src

2 files changed

+37
-0
lines changed

hibernate-orm-rest-data-panache-quickstart/src/main/java/org/acme/hibernate/orm/panache/rest/entity/Person.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.acme.hibernate.orm.panache.rest.entity;
22

33
import java.time.LocalDate;
4+
import java.util.Map;
5+
6+
import org.hibernate.annotations.JdbcTypeCode;
7+
import org.hibernate.type.SqlTypes;
48

59
import jakarta.persistence.Entity;
610
import jakarta.persistence.NamedQuery;
@@ -12,4 +16,7 @@
1216
public class Person extends PanacheEntity {
1317
public String name;
1418
public LocalDate birthDate;
19+
20+
@JdbcTypeCode(SqlTypes.JSON)
21+
public Map<String, Object> jsonAddress;
1522
}

hibernate-orm-rest-data-panache-quickstart/src/test/java/org/acme/hibernate/orm/panache/rest/entity/PeopleResourceTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import static org.hamcrest.Matchers.equalTo;
77
import static org.hamcrest.Matchers.is;
88

9+
import java.time.LocalDate;
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
913
import org.apache.http.HttpStatus;
1014
import org.junit.jupiter.api.Test;
1115

@@ -113,4 +117,30 @@ void shouldDeleteNotBeExposed() {
113117
given().when().delete("/my-people/1")
114118
.then().statusCode(405);
115119
}
120+
121+
@Test
122+
void shouldUpdatePerson() {
123+
124+
Person newPerson = new Person();
125+
newPerson.name = "Holly";
126+
newPerson.birthDate = LocalDate.of(2001, 11, 20);
127+
128+
Map<String, Object> jsonObject = new HashMap<>();
129+
jsonObject.put("zipcode", 95014);
130+
jsonObject.put("city", "cupertino");
131+
newPerson.jsonAddress = jsonObject;
132+
133+
given().accept(ContentType.JSON).and().contentType(ContentType.JSON).and().body(newPerson).when()
134+
.put("/my-people/1").then().statusCode(204);
135+
136+
// verify after updating that the new json address fields were stored
137+
given().accept(ContentType.JSON)
138+
.when().get("/my-people/1")
139+
.then().statusCode(200)
140+
.and().body("id", is(equalTo(1)))
141+
.and().body("name", is(equalTo("Holly")))
142+
.and().body("jsonAddress", is( equalTo(jsonObject)));
143+
144+
}
145+
116146
}

0 commit comments

Comments
 (0)