diff --git a/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/RequestParameters.java b/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/RequestParameters.java index 6bca3150b4..cd9d92a8f0 100644 --- a/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/RequestParameters.java +++ b/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/RequestParameters.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 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 @@ -156,7 +156,7 @@ private void addBeanParameter(final Object beanParam) anns.put(ann.annotationType(), ann); } - if (hasAnyParamAnnotation(anns)) { + if (field.canAccess(beanParam) && hasAnyParamAnnotation(anns)) { value = field.get(beanParam); } else { // get getter annotations if there are no field annotations diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyBeanParamWithPrivateField.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyBeanParamWithPrivateField.java new file mode 100644 index 0000000000..beb98f6461 --- /dev/null +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyBeanParamWithPrivateField.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 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.client.proxy; + + +import jakarta.ws.rs.QueryParam; + +/** + * @author Divyansh Shekhar Gaur + */ +public class MyBeanParamWithPrivateField { + + @QueryParam("privateFieldParam") + private String privateFieldParam; + + public MyBeanParamWithPrivateField() {} + + public String getPrivateFieldParam() { + return privateFieldParam; + } + + public void setPrivateFieldParam(String privateFieldParam) { + this.privateFieldParam = privateFieldParam; + } +} diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceWithBeanParam.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceWithBeanParam.java index 1b49f50026..81fd9b47ea 100644 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceWithBeanParam.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceWithBeanParam.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024 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 @@ -53,6 +53,11 @@ public String echoSubBean(@BeanParam MyGetBeanParam bean) { return bean.getSubBeanParam().getSubQueryParam().toString(); } + @Override + public String echoPrivateField(@BeanParam MyBeanParamWithPrivateField bean) { + return bean.getPrivateFieldParam(); + } + @Override public String echo(MyBeanParam bean) { return ("HEADER=" + bean.getHeaderParam() + ",PATH=" + bean.getPathParam() + ",FORM=" diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceWithBeanParamIfc.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceWithBeanParamIfc.java index 5e73615407..f4b7f5c025 100644 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceWithBeanParamIfc.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceWithBeanParamIfc.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024 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 @@ -59,6 +59,12 @@ public interface MyResourceWithBeanParamIfc { @Produces("text/plain") public String echoSubBean(@BeanParam MyGetBeanParam bean); + @POST + @Consumes("application/x-www-form-urlencoded") + @Path("getPrivateField") + @Produces("text/plain") + public String echoPrivateField(@BeanParam MyBeanParamWithPrivateField bean); + @POST @Consumes("application/x-www-form-urlencoded") @Path("all/{pathParam}") diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryBeanParamTest.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryBeanParamTest.java index d9b361a27e..6819e0cde8 100644 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryBeanParamTest.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryBeanParamTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024 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 @@ -138,4 +138,14 @@ public void testSubResource() { assertEquals("query", response); } + + @Test + public void testBeanParamPrivateFieldQuery() { + MyBeanParamWithPrivateField myGetBeanParam = new MyBeanParamWithPrivateField(); + myGetBeanParam.setPrivateFieldParam("query"); + + String response = resourceWithBeanParam.echoPrivateField(myGetBeanParam); + + assertEquals("query", response); + } } \ No newline at end of file