diff --git a/bom/pom.xml b/bom/pom.xml index 5f17d65c24..9522a3808b 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -268,11 +268,6 @@ jersey-media-json-jackson ${project.version} - - org.glassfish.jersey.media - jersey-media-json-jackson1 - ${project.version} - org.glassfish.jersey.media jersey-media-json-jettison diff --git a/bundles/examples/pom.xml b/bundles/examples/pom.xml index 028a380c0d..00fdb81ff5 100644 --- a/bundles/examples/pom.xml +++ b/bundles/examples/pom.xml @@ -345,13 +345,6 @@ project-src zip - - org.glassfish.jersey.examples - json-jackson1 - ${project.version} - project-src - zip - org.glassfish.jersey.examples json-jettison diff --git a/examples/json-jackson1/README.MD b/examples/json-jackson1/README.MD deleted file mode 100644 index feb7fa2449..0000000000 --- a/examples/json-jackson1/README.MD +++ /dev/null @@ -1,91 +0,0 @@ -[//]: # " Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. " -[//]: # " " -[//]: # " This program and the accompanying materials are made available under the " -[//]: # " terms of the Eclipse Distribution License v. 1.0, which is available at " -[//]: # " http://www.eclipse.org/org/documents/edl-v10.php. " -[//]: # " " -[//]: # " SPDX-License-Identifier: BSD-3-Clause " - -Jackson (1.x) JAX-RS JSON Provider Example -========================================== - -This example demonstrates how to produce/consume JSON representations -from Java objects. This applies not only to JAXB beans, as shown in the -`json-from-jaxb` example but also to ordinary, un-annotated, POJOs. - -This example hosts three simple read-only resources: One provides an -example of using a Jackson JSON provider (registered by the feature -`Jackson1Feature` in the `MyApplication` class) instead of using JAXB -(Object->JAXB->JSON) which has some limitations (e.g. empty arrays -in JAXB beans). For this resource the JSON representation is produced by -the Jackson JAX-RS provider, while the XML representation is generated -by JAXB as usual. The second web resource is based on a simple -un-annotated POJO and provides only JSON-based representations: JSON and -JSON with padding (JSONP). The third resource depicts how Jackson and -JAXB annotations could be mixed together within a single POJO. - -Contents --------- - -The "empty array" web resource is implemented by the -`org.glassfish.jersey.examples.jackson1.EmptyArrayResource` class. - -The "non JAXB" web resource is implemented by the -`org.glassfish.jersey.examples.jackson1.NonJaxbBeanResource` class. - -Both resources use the default Jackson mapper configuration to serialize JSON -data out and depicts the corner cases, where the Jersey internal, StAX -based, JSON processing can not be utilized. - -The `org.glassfish.jersey.examples.jackson1.CombinedAnnotationResource` -class is used to show how JAXB and Jackson annotations could be combined -together in one Java bean for JSON serialization. - -See the `org.glassfish.jersey.examples.jackson1.MyObjectMapperProvider` class -where Jackson specific options are used to set up the desired JSON -serialization configuration. - -The mapping of the URI path space is presented in the following table: - -URI path | Resource class | HTTP method ----------------------------- | ---------------------------- | ------------- -**_/emptyArrayResource_** | EmptyArrayResource | GET -**_/nonJaxbResource_** | NonJaxbBeanResource | GET -**_/combinedAnnotations_** | CombinedAnnotationResource | GET - -To use Jackson specific configuration options, one can implement a -`ContextResolver` provider. For an example of such an -implementation, see the `MyObjectMapperProvider` class. - -Running the Example -------------------- - -Run the example as follows: - -> mvn clean compile exec:java - -This deploys the example using [Grizzly](http://grizzly.java.net/) - -A [WADL description](http://wadl.java.net/#spec) may be accessed at the URL: - -- `http://localhost:8080/jackson1/application.wadl` - -The three resources are available at - -- -- -- - -To easily obtain the different output types available, [cURL](http://curl.haxx.se/) can be used as follows: - -Obtain the JSON output of EmptyArrayResource (use `-HAccept:application/xml` for XML output): - -> curl -HAccept:application/json http://localhost:8080/jackson1/emptyArrayResource - -Obtain the JSON output of NonJaxbBeanResource (use `-HAccept:application/javascript` for JSONP output): - -> curl -HAccept:application/json http://localhost:8080/jackson1/nonJaxbResource - -Obtain the JSON output of CombinedAnnotationResource: - -> curl -HAccept:application/json http://localhost:8080/jackson1/combinedAnnotations diff --git a/examples/json-jackson1/pom.xml b/examples/json-jackson1/pom.xml deleted file mode 100644 index 63ce32d7f2..0000000000 --- a/examples/json-jackson1/pom.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - - 4.0.0 - - - org.glassfish.jersey.examples - project - 3.0-SNAPSHOT - - - json-jackson1 - jar - jersey-examples-json-jackson1 - - Jersey JSON with Jackson 1.x example. - - - - org.glassfish.jersey.containers - jersey-container-grizzly2-http - - - org.glassfish.jersey.inject - jersey-hk2 - - - org.glassfish.jersey.media - jersey-media-json-jackson1 - - - - org.glassfish.jersey.test-framework.providers - jersey-test-framework-provider-bundle - pom - test - - - - - - - org.codehaus.mojo - exec-maven-plugin - - org.glassfish.jersey.examples.jackson1.App - - - - - - - - jdk11+ - - [11,) - - - - com.sun.xml.bind - jaxb-osgi - test - - - - - pre-release - - - - org.apache.maven.plugins - maven-assembly-plugin - - - - - - - diff --git a/examples/json-jackson1/src/main/assembly/src.xml b/examples/json-jackson1/src/main/assembly/src.xml deleted file mode 100644 index a030433f94..0000000000 --- a/examples/json-jackson1/src/main/assembly/src.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - project - - zip - - - - . - - true - - **/target/** - - - - diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/App.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/App.java deleted file mode 100644 index 178df0acc6..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/App.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import java.io.IOException; -import java.net.URI; -import java.util.logging.Level; -import java.util.logging.Logger; - - -import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; -import org.glassfish.jersey.server.ResourceConfig; - -import org.glassfish.grizzly.http.server.HttpServer; - -/** - * Utility class which creates {@link MyApplication} instances and provides support - * for running this sample from command line. - * - * @author Jakub Podlesak - */ -public class App { - - private static final URI BASE_URI = URI.create("http://localhost:8080/jackson1/"); - - public static void main(final String[] args) { - try { - System.out.println("JSON with Jackson Jersey Example App"); - - final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false); - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - @Override - public void run() { - server.shutdownNow(); - } - })); - server.start(); - - System.out.println(String.format("Application started.%nStop the application using CTRL+C")); - - Thread.currentThread().join(); - } catch (IOException | InterruptedException ex) { - Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); - } - - } - - public static ResourceConfig createApp() { - return new MyApplication(); - } -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/CombinedAnnotationBean.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/CombinedAnnotationBean.java deleted file mode 100644 index 5470a2c806..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/CombinedAnnotationBean.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import javax.xml.bind.annotation.XmlRootElement; -import org.codehaus.jackson.annotate.JsonProperty; - -/** - * @author Jakub Podlesak - */ -@XmlRootElement(name = "account") -public class CombinedAnnotationBean { - - @JsonProperty("value") - int x; - - public CombinedAnnotationBean(final int x) { - this.x = x; - } - - public CombinedAnnotationBean() { - this(15); - } -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/CombinedAnnotationResource.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/CombinedAnnotationResource.java deleted file mode 100644 index 0613839f73..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/CombinedAnnotationResource.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; - -/** - * @author Jakub Podlesak - */ -@Path("combinedAnnotations") -public class CombinedAnnotationResource { - - @Produces(MediaType.APPLICATION_JSON) - @GET - public CombinedAnnotationBean getAccount() { - return new CombinedAnnotationBean(12); - } -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/DummyBean.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/DummyBean.java deleted file mode 100644 index 2b42ea0d3a..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/DummyBean.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -/** - * Testing bean for ExceptionMappingTestResource. - * - * @author Jakub Podlesak - */ -public class DummyBean { - - private int key; - private String value; - - public String getValue() { - return value; - } - - public void setValue(final String value) { - this.value = value; - } - - public int getKey() { - return key; - } - - public void setKey(final int key) { - this.key = key; - } - -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/EmptyArrayBean.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/EmptyArrayBean.java deleted file mode 100644 index e22c38e839..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/EmptyArrayBean.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import javax.xml.bind.annotation.XmlRootElement; - -/** - * @author Jakub Podlesak - */ -@XmlRootElement -public class EmptyArrayBean { - - public String[] emtpyArray = new String[0]; -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/EmptyArrayResource.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/EmptyArrayResource.java deleted file mode 100644 index 79d06662dc..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/EmptyArrayResource.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; - -/** - * @author Jakub Podlesak - */ -@Path("/emptyArrayResource") -public class EmptyArrayResource { - - // the resource JSON representation will be serialized by Jackson JAX-RS provider, - // while the XML will still be generated by JAXB - @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public EmptyArrayBean getIt() { - return new EmptyArrayBean(); - } -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/ExceptionMappingTestResource.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/ExceptionMappingTestResource.java deleted file mode 100644 index be5560d285..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/ExceptionMappingTestResource.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2014, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.PUT; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.core.MediaType; - -/** - * Testing bean that accepts JSON for the PUT method. - * - * @author Adam Lindenthal - */ -@Path("parseExceptionTest") -public class ExceptionMappingTestResource { - - @Consumes(MediaType.APPLICATION_JSON) - @PUT - public DummyBean getAccount(final DummyBean bean) { - return bean; - } -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/MyApplication.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/MyApplication.java deleted file mode 100644 index 51d4f4ec7b..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/MyApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import org.glassfish.jersey.jackson1.Jackson1Feature; -import org.glassfish.jersey.server.ResourceConfig; - -/** - * {@link jakarta.ws.rs.core.Application} descendant. - * - * Used to set resource and providers classes. - * - * @author Jakub Podlesak - */ -public class MyApplication extends ResourceConfig { - - public MyApplication() { - super( - EmptyArrayResource.class, - NonJaxbBeanResource.class, - CombinedAnnotationResource.class, - // register Jackson ObjectMapper resolver - MyObjectMapperProvider.class, - ExceptionMappingTestResource.class, - Jackson1Feature.class - ); - } -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/MyObjectMapperProvider.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/MyObjectMapperProvider.java deleted file mode 100644 index 7f7cd67999..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/MyObjectMapperProvider.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import jakarta.ws.rs.ext.ContextResolver; -import jakarta.ws.rs.ext.Provider; - -import org.codehaus.jackson.map.AnnotationIntrospector; -import org.codehaus.jackson.map.AnnotationIntrospector.Pair; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; -import org.codehaus.jackson.map.SerializationConfig.Feature; -import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector; -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; - -/** - * @author Jakub Podlesak - */ -@Provider -public class MyObjectMapperProvider implements ContextResolver { - - final ObjectMapper defaultObjectMapper; - final ObjectMapper combinedObjectMapper; - - public MyObjectMapperProvider() { - defaultObjectMapper = createDefaultMapper(); - combinedObjectMapper = createCombinedObjectMapper(); - } - - @Override - public ObjectMapper getContext(final Class type) { - - if (type == CombinedAnnotationBean.class) { - return combinedObjectMapper; - } else { - return defaultObjectMapper; - } - } - - private static ObjectMapper createCombinedObjectMapper() { - final Pair combinedIntrospector = createJaxbJacksonAnnotationIntrospector(); - final ObjectMapper result = new ObjectMapper(); - result.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true); - result.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); - result.setDeserializationConfig(result.getDeserializationConfig().withAnnotationIntrospector(combinedIntrospector)); - result.setSerializationConfig(result.getSerializationConfig().withAnnotationIntrospector(combinedIntrospector)); - - return result; - } - - private static ObjectMapper createDefaultMapper() { - - final ObjectMapper result = new ObjectMapper(); - result.configure(Feature.INDENT_OUTPUT, true); - - return result; - } - - private static Pair createJaxbJacksonAnnotationIntrospector() { - - final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(); - final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); - - return new AnnotationIntrospector.Pair(jacksonIntrospector, jaxbIntrospector); - } -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/NonJaxbBean.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/NonJaxbBean.java deleted file mode 100644 index 0b1f33faa3..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/NonJaxbBean.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -/** - * @author Jakub Podlesak - */ -public class NonJaxbBean { - - private String name = "non-JAXB-bean"; - private String description = "I am not a JAXB bean, just an unannotated POJO"; - private int[] array = {1, 1, 2, 3, 5, 8, 13, 21}; - - public int[] getArray() { - return array; - } - - public void setArray(final int[] array) { - this.array = array; - } - - public String getDescription() { - return description; - } - - public void setDescription(final String description) { - this.description = description; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } -} diff --git a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/NonJaxbBeanResource.java b/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/NonJaxbBeanResource.java deleted file mode 100644 index e6dc97dc76..0000000000 --- a/examples/json-jackson1/src/main/java/org/glassfish/jersey/examples/jackson1/NonJaxbBeanResource.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; - -import org.glassfish.jersey.server.JSONP; - -/** - * @author Jakub Podlesak - */ -@Path("/nonJaxbResource") -public class NonJaxbBeanResource { - - @GET - @JSONP - @Produces({"application/javascript", MediaType.APPLICATION_JSON}) - public NonJaxbBean getSimpleBeanJSONP() { - return new NonJaxbBean(); - } -} diff --git a/examples/json-jackson1/src/test/java/org/glassfish/jersey/examples/jackson1/Jackson1Test.java b/examples/json-jackson1/src/test/java/org/glassfish/jersey/examples/jackson1/Jackson1Test.java deleted file mode 100644 index 58e94c684b..0000000000 --- a/examples/json-jackson1/src/test/java/org/glassfish/jersey/examples/jackson1/Jackson1Test.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.glassfish.jersey.examples.jackson1; - -import jakarta.ws.rs.client.Entity; -import jakarta.ws.rs.client.WebTarget; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.Response; - -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.jackson1.Jackson1Feature; -import org.glassfish.jersey.message.internal.MediaTypes; -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.test.JerseyTest; -import org.glassfish.jersey.test.TestProperties; - -import org.junit.Ignore; -import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * @author Jakub Podlesak - */ -public class Jackson1Test extends JerseyTest { - - @Override - protected ResourceConfig configure() { - enable(TestProperties.LOG_TRAFFIC); - enable(TestProperties.DUMP_ENTITY); - - return App.createApp(); - } - - @Override - protected void configureClient(final ClientConfig config) { - config.register(Jackson1Feature.class).register(MyObjectMapperProvider.class); - } - - @Test - public void testEmptyArrayPresent() { - final String responseMsg = target("emptyArrayResource").request(MediaType.APPLICATION_JSON).get(String.class); - assertTrue(responseMsg.replaceAll("[ \t]*", "").contains("[]")); - } - - @Test - public void testJSONPPresent() { - final String responseMsg = target("nonJaxbResource").request("application/javascript").get(String.class); - assertTrue(responseMsg.startsWith("callback(")); - } - - @Test - public void testJSONDoesNotReflectJSONPWrapper() { - final String responseMsg = target("nonJaxbResource").request("application/json").get(String.class); - assertTrue(!responseMsg.contains("jsonSource")); - } - - @Test - public void testCombinedAnnotationResource() { - final String responseMsg = target("combinedAnnotations").request("application/json").get(String.class); - assertTrue(responseMsg.contains("account") && responseMsg.contains("value")); - } - - @Test - public void testEmptyArrayBean() { - assertNotNull(target("emptyArrayResource").request(MediaType.APPLICATION_JSON).get(EmptyArrayBean.class)); - } - - @Test - public void testCombinedAnnotationBean() { - assertNotNull(target("combinedAnnotations").request("application/json").get(CombinedAnnotationBean.class)); - } - - @Test - @Ignore - // TODO un-ignore once a JSON reader for "application/javascript" is supported - public void testJSONPBean() { - assertNotNull(target("nonJaxbResource").request("application/javascript").get(NonJaxbBean.class)); - } - - /** - * Test if a WADL document is available at the relative path - * "application.wadl". - *

- */ - @Test - public void testApplicationWadl() { - final WebTarget target = target(); - final String serviceWadl = target.path("application.wadl").request(MediaTypes.WADL_TYPE).get(String.class); - - assertTrue(serviceWadl.length() > 0); - } - - /** - * Test, that in case of malformed JSON, the jackson exception mappers will be used and the response will be - * 400 - bad request instead of 500 - server error - */ - @Test - public void testExceptionMapping() { - enable(TestProperties.LOG_TRAFFIC); - // create a request with invalid json string to cause an exception in Jackson - final Response response = target().path("parseExceptionTest").request("application/json") - .put(Entity.entity("Malformed json string.", MediaType.valueOf("application/json"))); - - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - } -} diff --git a/examples/pom.xml b/examples/pom.xml index a2b9e133ae..9c312426cc 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -90,7 +90,6 @@ jersey-ejb json-binding-webapp json-jackson - json-jettison diff --git a/media/json-jackson1/pom.xml b/media/json-jackson1/pom.xml deleted file mode 100644 index 7edc05831c..0000000000 --- a/media/json-jackson1/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - 4.0.0 - - - org.glassfish.jersey.media - project - 3.0-SNAPSHOT - - - jersey-media-json-jackson1 - jar - jersey-media-json-jackson1 - - - Jersey JSON Jackson (1.x) entity providers support module. - - - - - - com.sun.istack - istack-commons-maven-plugin - true - - - org.codehaus.mojo - build-helper-maven-plugin - true - - - org.apache.felix - maven-bundle-plugin - true - true - - - org.glassfish.jersey.jackson1.* - - true - - - - - - - - org.glassfish.jersey.core - jersey-common - ${project.version} - - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-mapper-asl - - - org.codehaus.jackson - jackson-jaxrs - - - org.codehaus.jackson - jackson-xc - - - - junit - junit - test - - - diff --git a/media/json-jackson1/src/main/java/org/glassfish/jersey/jackson1/Jackson1Feature.java b/media/json-jackson1/src/main/java/org/glassfish/jersey/jackson1/Jackson1Feature.java deleted file mode 100644 index 96b2d72227..0000000000 --- a/media/json-jackson1/src/main/java/org/glassfish/jersey/jackson1/Jackson1Feature.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.jersey.jackson1; - -import jakarta.ws.rs.core.Configuration; -import jakarta.ws.rs.core.Feature; -import jakarta.ws.rs.core.FeatureContext; -import jakarta.ws.rs.ext.MessageBodyReader; -import jakarta.ws.rs.ext.MessageBodyWriter; - -import org.glassfish.jersey.CommonProperties; -import org.glassfish.jersey.internal.InternalProperties; -import org.glassfish.jersey.internal.util.PropertiesHelper; - -import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider; -import org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper; -import org.codehaus.jackson.jaxrs.JsonParseExceptionMapper; - -/** - * Feature used to register Jackson (1.x) JSON providers. - * - * @author Stepan Kopriva - * @author Michal Gajdos - */ -public final class Jackson1Feature implements Feature { - - private static final String JSON_FEATURE = Jackson1Feature.class.getSimpleName(); - - @Override - public boolean configure(final FeatureContext context) { - final Configuration config = context.getConfiguration(); - - final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), - InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class); - // Other JSON providers registered. - if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) { - return false; - } - - // Disable other JSON providers. - context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), - JSON_FEATURE); - - // add the default Jackson exception mappers - context.register(JsonParseExceptionMapper.class); - context.register(JsonMappingExceptionMapper.class); - context.register(JacksonJaxbJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class); - return true; - } -} diff --git a/media/json-jackson1/src/main/java/org/glassfish/jersey/jackson1/package-info.java b/media/json-jackson1/src/main/java/org/glassfish/jersey/jackson1/package-info.java deleted file mode 100644 index 706055de5e..0000000000 --- a/media/json-jackson1/src/main/java/org/glassfish/jersey/jackson1/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -/** - * Jersey classes supporting JSON media type processing based on Jackson 1.x. - */ -package org.glassfish.jersey.jackson1; diff --git a/media/pom.xml b/media/pom.xml index 47b258832e..e5e2ea9fbe 100644 --- a/media/pom.xml +++ b/media/pom.xml @@ -39,7 +39,6 @@ jaxb json-binding json-jackson - json-jackson1 json-jettison diff --git a/pom.xml b/pom.xml index a997effb15..990ff5412d 100644 --- a/pom.xml +++ b/pom.xml @@ -1760,30 +1760,6 @@ ${jackson.version} - - org.codehaus.jackson - jackson-core-asl - ${jackson1.version} - - - - org.codehaus.jackson - jackson-mapper-asl - ${jackson1.version} - - - - org.codehaus.jackson - jackson-jaxrs - ${jackson1.version} - - - - org.codehaus.jackson - jackson-xc - ${jackson1.version} - - xerces xercesImpl @@ -2118,7 +2094,6 @@ 4.5.9 3.0.8 2.10.1 - 1.9.13 1.2.1 3.25.0-GA javax.annotation.*;version="[1.2,3)" diff --git a/tests/e2e-client/pom.xml b/tests/e2e-client/pom.xml index b114217e79..035ae46559 100644 --- a/tests/e2e-client/pom.xml +++ b/tests/e2e-client/pom.xml @@ -91,11 +91,6 @@ jersey-media-json-jackson test - - org.glassfish.jersey.media - jersey-media-json-jackson1 - test - org.glassfish.jersey.media jersey-media-json-jettison diff --git a/tests/e2e-entity/pom.xml b/tests/e2e-entity/pom.xml index 12637271bb..8e964502f0 100644 --- a/tests/e2e-entity/pom.xml +++ b/tests/e2e-entity/pom.xml @@ -110,11 +110,6 @@ jersey-media-json-jackson test - - org.glassfish.jersey.media - jersey-media-json-jackson1 - test - org.glassfish.jersey.media jersey-media-json-jettison diff --git a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/Jackson1JsonViewTest.java b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/Jackson1JsonViewTest.java deleted file mode 100644 index 3dadb5ee2c..0000000000 --- a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/Jackson1JsonViewTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2014, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.jersey.tests.e2e.json; - -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.container.AsyncResponse; -import jakarta.ws.rs.container.Suspended; -import jakarta.ws.rs.core.Application; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.Response; - -import javax.inject.Singleton; - -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.jackson1.Jackson1Feature; -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.test.JerseyTest; - -import org.codehaus.jackson.map.annotate.JsonView; -import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * Reproducer for JERSEY-1878. - * - * @author Michal Gajdos - */ -public class Jackson1JsonViewTest extends JerseyTest { - - @Override - protected Application configure() { - return new ResourceConfig(MyResource.class, Jackson1Feature.class); - } - - @Override - protected void configureClient(final ClientConfig config) { - config.register(Jackson1Feature.class); - } - - public static class SimpleView {} - public static class DetailedView {} - - public static class TestEntity { - - public static final TestEntity ENTITY = new TestEntity("simple", "detailed"); - public static final TestEntity DETAILED = new TestEntity(null, "detailed"); - - private String simple; - private String detailed; - - public TestEntity() { - } - - public TestEntity(final String simple, final String detailed) { - this.simple = simple; - this.detailed = detailed; - } - - @JsonView(SimpleView.class) - public String getSimple() { - return simple; - } - - @JsonView(DetailedView.class) - public String getDetailed() { - return detailed; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - final TestEntity that = (TestEntity) o; - - if (detailed != null ? !detailed.equals(that.detailed) : that.detailed != null) { - return false; - } - if (simple != null ? !simple.equals(that.simple) : that.simple != null) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = simple != null ? simple.hashCode() : 0; - result = 31 * result + (detailed != null ? detailed.hashCode() : 0); - return result; - } - } - - @Path("/") - @Singleton - public static class MyResource { - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("async") - @JsonView(DetailedView.class) - public void getAsync(@Suspended final AsyncResponse response) { - response.resume(TestEntity.ENTITY); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("sync") - @JsonView(DetailedView.class) - public TestEntity getSync() { - return TestEntity.ENTITY; - } - } - - @Test - public void testSync() throws Exception { - final Response response = target().path("sync").request().get(); - - assertThat(response.getStatus(), is(200)); - assertThat(response.readEntity(TestEntity.class), is(TestEntity.DETAILED)); - } - - @Test - public void testAsync() throws Exception { - final Response response = target().path("async").request().async().get().get(); - - assertThat(response.getStatus(), is(200)); - assertThat(response.readEntity(TestEntity.class), is(TestEntity.DETAILED)); - - response.close(); - } -} diff --git a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/JsonTestProvider.java b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/JsonTestProvider.java index 10c3bee5b9..2d25acf11c 100644 --- a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/JsonTestProvider.java +++ b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/JsonTestProvider.java @@ -31,7 +31,6 @@ import javax.json.bind.JsonbConfig; import org.glassfish.jersey.jackson.JacksonFeature; -import org.glassfish.jersey.jackson1.Jackson1Feature; import org.glassfish.jersey.jettison.JettisonConfig; import org.glassfish.jersey.jettison.JettisonFeature; import org.glassfish.jersey.jsonb.JsonBindingFeature; @@ -47,7 +46,6 @@ public abstract class JsonTestProvider { public static final Collection JAXB_PROVIDERS = new LinkedHashSet() {{ add(new JacksonJsonTestProvider()); - add(new Jackson1JsonTestProvider()); add(new JettisonMappedJsonTestProvider()); add(new JettisonBadgerfishJsonTestProvider()); add(new MoxyJsonTestProvider()); @@ -57,7 +55,6 @@ public abstract class JsonTestProvider { // TODO add MoxyJsonTestProvider once MOXy supports POJO public static final Collection POJO_PROVIDERS = new LinkedHashSet() {{ add(new JacksonJsonTestProvider()); - add(new Jackson1JsonTestProvider()); }}; private Feature feature; diff --git a/tests/e2e-server/pom.xml b/tests/e2e-server/pom.xml index e1683acd0d..27800f42ef 100644 --- a/tests/e2e-server/pom.xml +++ b/tests/e2e-server/pom.xml @@ -90,11 +90,6 @@ jersey-media-json-jackson test - - org.glassfish.jersey.media - jersey-media-json-jackson1 - test - org.glassfish.jersey.media jersey-media-json-jettison diff --git a/tests/e2e/pom.xml b/tests/e2e/pom.xml index 7c689a6621..f7b2b86fd0 100644 --- a/tests/e2e/pom.xml +++ b/tests/e2e/pom.xml @@ -93,11 +93,6 @@ jersey-media-json-jackson test - - org.glassfish.jersey.media - jersey-media-json-jackson1 - test - org.glassfish.jersey.media jersey-media-json-jettison diff --git a/tests/osgi/functional/pom.xml b/tests/osgi/functional/pom.xml index 83257cfc70..7e1959ac52 100644 --- a/tests/osgi/functional/pom.xml +++ b/tests/osgi/functional/pom.xml @@ -50,7 +50,6 @@ org/glassfish/jersey/osgi/test/basic/JsonMoxyTest.java org/glassfish/jersey/osgi/test/basic/JsonProcessingTest.java - org/glassfish/jersey/osgi/test/basic/JsonJackson1Test.java @@ -205,11 +204,6 @@ jersey-media-json-jackson test - - org.glassfish.jersey.media - jersey-media-json-jackson1 - test - org.glassfish.jersey.media jersey-media-json-jettison @@ -352,27 +346,6 @@ test - - org.codehaus.jackson - jackson-core-asl - test - - - org.codehaus.jackson - jackson-mapper-asl - test - - - org.codehaus.jackson - jackson-jaxrs - test - - - org.codehaus.jackson - jackson-xc - test - - com.sun.xml.bind jaxb-osgi @@ -409,7 +382,6 @@ org/glassfish/jersey/osgi/test/basic/JsonMoxyTest.java org/glassfish/jersey/osgi/test/basic/JsonProcessingTest.java - org/glassfish/jersey/osgi/test/basic/JsonJackson1Test.java @@ -428,6 +400,32 @@ ${jakarta.activation.version} + sonar diff --git a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonJackson1Test.java b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonJackson1Test.java deleted file mode 100644 index 2bdc6972fd..0000000000 --- a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonJackson1Test.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2014, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.jersey.osgi.test.basic; - -import java.util.ArrayList; -import java.util.List; - -import jakarta.ws.rs.core.Feature; - -import org.glassfish.jersey.jackson1.Jackson1Feature; -import org.glassfish.jersey.osgi.test.util.Helper; - -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; - -/** - * @author Michal Gajdos - */ -public class -JsonJackson1Test extends AbstractJsonOsgiIntegrationTest { - - @Configuration - public static Option[] configuration() { - final List