diff --git a/README.md b/README.md index 772f67712697bfde79b9ce1587a61596418ed39f..7e1a0ab302cf32ce61063cd645cad5a32122cb70 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ 4. curl http://localhost:8080/restApp/sample/persons 5. curl -H "Content-Type: application/json" \ -X POST \ - -d '{"name":"Jeanne"}' \ + -d '{"Person":{"name":"Jeanne"}}' \ http://localhost:8080/restApp/sample/persons 6. curl http://localhost:8080/restApp-1.0-SNAPSHOT/resources/sample/persons/843c8236-6c6b-450e-9aa3-211a9b897403 7. curl -H "Accept: text/xml" http://localhost:8080/restApp-1.0-SNAPSHOT/resources/sample/persons diff --git a/entites/pom.xml b/entites/pom.xml index 6ad01bf0328715cf90e865f6c11f7e85620ef270..3f77f5dd0b4c1c3234cb7800da73213d1b5a6669 100644 --- a/entites/pom.xml +++ b/entites/pom.xml @@ -20,6 +20,11 @@ <artifactId>jakarta.jakartaee-api</artifactId> <scope>provided</scope> </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.jakarta.rs</groupId> + <artifactId>jackson-jakarta-rs-json-provider</artifactId> + </dependency> </dependencies> </project> \ No newline at end of file diff --git a/entites/src/main/java/fr/univtln/bruno/samples/jee91/dao/Person.java b/entites/src/main/java/fr/univtln/bruno/samples/jee91/dao/Person.java index b3bdcf85113dbc5920c50e441cffee5c626fd594..a57a6c3c94bb3bdb5ad86b4ca2649715b9272a63 100644 --- a/entites/src/main/java/fr/univtln/bruno/samples/jee91/dao/Person.java +++ b/entites/src/main/java/fr/univtln/bruno/samples/jee91/dao/Person.java @@ -1,6 +1,9 @@ package fr.univtln.bruno.samples.jee91.dao; -import jakarta.json.bind.annotation.JsonbTransient; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; @@ -28,11 +31,13 @@ import java.util.UUID; query = "SELECT p FROM Person p WHERE p.uuid=:uuid") @XmlRootElement @FieldDefaults(level = AccessLevel.PRIVATE) +@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME) public class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") - @JsonbTransient + + @JsonIgnore long id; @ToString.Include diff --git a/jee/ear/pom.xml b/jee/ear/pom.xml index be6d22619290563f3a78034fb65df23eb4b08edd..942e5682adeefde1dfe60075e544bed3b447f415 100644 --- a/jee/ear/pom.xml +++ b/jee/ear/pom.xml @@ -53,7 +53,6 @@ <version>1.0-SNAPSHOT</version> </dependency> - </dependencies> <build> diff --git a/jee/restApp/src/main/java/fr/univtln/bruno/samples/jee91/rs/JAXRSConfiguration.java b/jee/restApp/src/main/java/fr/univtln/bruno/samples/jee91/rs/JAXRSConfiguration.java index 5e8e933a80afc176a4784d0f0af77724005c9064..9854eedc8f8b5203f4504b6b92ce18081b117aa7 100644 --- a/jee/restApp/src/main/java/fr/univtln/bruno/samples/jee91/rs/JAXRSConfiguration.java +++ b/jee/restApp/src/main/java/fr/univtln/bruno/samples/jee91/rs/JAXRSConfiguration.java @@ -4,7 +4,15 @@ package fr.univtln.bruno.samples.jee91.rs; import jakarta.ws.rs.ApplicationPath; import jakarta.ws.rs.core.Application; +import java.util.HashMap; +import java.util.Map; + @ApplicationPath("/") public class JAXRSConfiguration extends Application { - + @Override + public Map<String, Object> getProperties() { + var properties = new HashMap<String, Object>(); + properties.put("jersey.config.jsonFeature", "JacksonFeature"); + return properties; + } } \ No newline at end of file diff --git a/jee/restApp/src/main/webapp/WEB-INF/web.xml b/jee/restApp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..4c8ad734f9c29e7b614ef8336c42233648b76927 --- /dev/null +++ b/jee/restApp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd" + version="5.0"> +</web-app> \ No newline at end of file diff --git a/jee/wsApp/src/main/resources/META-INF/log4j.properties b/jee/wsApp/src/main/resources/log4j.properties similarity index 100% rename from jee/wsApp/src/main/resources/META-INF/log4j.properties rename to jee/wsApp/src/main/resources/log4j.properties diff --git a/pom.xml b/pom.xml index 2890842f2fbb5e8bc58e34827130fb38c12d4d60..3f7050992ec194e5b6176569b9b6042348a850fa 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,13 @@ <artifactId>slf4j-log4j12</artifactId> <version>1.7.32</version> </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.jakarta.rs</groupId> + <artifactId>jackson-jakarta-rs-json-provider</artifactId> + <version>2.13.0</version> + </dependency> + </dependencies> </dependencyManagement>