Skip to content

Commit

Permalink
Adding org.json.JSONObject example
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos committed Jul 1, 2022
1 parent 3aaad44 commit 26a7eff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,12 @@
<version>${gson.version}</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>

<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
Expand Down Expand Up @@ -2212,5 +2218,6 @@
<servlet4.version>4.0.4</servlet4.version>
<yasson.version>1.0.11</yasson.version>
<gson.version>2.9.0</gson.version>
<json.version>20220320</json.version>
</properties>
</project>
6 changes: 6 additions & 0 deletions tests/e2e-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@
<artifactId>xmlunit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.glassfish.jersey.gson.JsonGsonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.json.JSONObject;
import org.junit.Test;

public class GsonDefaultTest extends JerseyTest {
Expand All @@ -53,6 +54,15 @@ public Obj get() {
entity.setValue("get");
return entity;
}

@POST
@Consumes("application/json")
@Produces("application/json")
@Path("/jsonObject")
public JSONObject jsonObject(JSONObject entity) {
entity.put("bar", "bar");
return entity;
}
}

@Override
Expand Down Expand Up @@ -84,6 +94,17 @@ public void post() {
assertEquals("bar", obj.getValue());
}

@Test
public void jsonObject() {
JSONObject entity = new JSONObject();
entity.put("foo", "foo");
assertEquals("{\"foo\":\"foo\"}", entity.toString());
Response response = target("/test/jsonObject").request().post(Entity.json(entity));
assertEquals(200, response.getStatus());
entity = response.readEntity(JSONObject.class);
assertEquals("{\"foo\":\"foo\",\"bar\":\"bar\"}", entity.toString());
}

public static class Obj {
private String value;

Expand Down

0 comments on commit 26a7eff

Please sign in to comment.