• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use @GET with an input parameter of java type  RSS feed

 
Siko Siko
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am trying to create a webservice GET methods that takes in a java type as an input parameter. I am not sure which annotation to use infornt of that java type, I tried @QueryParam but was not able to get it to return result, always return an empty type.

@GET
@PRODUCES("application/xml")
public Name getName(Name name){
return name;
}


Name class:
@XMLRootElement
public class Name{
String firstName;
String lastName;
public Name(String a){}
//getters and setters
}


Any help is totally appreciated
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
If you are using a web service stack implementing the JAX-RS (JSR 311) specification, then take a look at sections 3.2 and 3.3.2.
The @QueryParam annotation is to be used if the parameter is a query URI parameter. Since you are implementing a method annotated with @GET, there will be no form data enclosed with the request and it will not be possible to enclose parameters that cannot be enclosed in the URI.
If you have a complex key type that, for instance, consists of two strings, and you want to use such a key to retrieve some resource then I suggest splitting the key into its primitive parts. Example of URI accessing such a resource:
.../myresource/keypart1/first_part_of_key_here/keypart2/second_part_of_key_here/
Alternatively:
.../myresource/first_part_of_key_here/second_part_of_key_here/
Best wishes!
 
Simona
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot! That worked.

Ivan Krizsan wrote:Hi!
If you are using a web service stack implementing the JAX-RS (JSR 311) specification, then take a look at sections 3.2 and 3.3.2.
The @QueryParam annotation is to be used if the parameter is a query URI parameter. Since you are implementing a method annotated with @GET, there will be no form data enclosed with the request and it will not be possible to enclose parameters that cannot be enclosed in the URI.
If you have a complex key type that, for instance, consists of two strings, and you want to use such a key to retrieve some resource then I suggest splitting the key into its primitive parts. Example of URI accessing such a resource:
.../myresource/keypart1/first_part_of_key_here/keypart2/second_part_of_key_here/
Alternatively:
.../myresource/first_part_of_key_here/second_part_of_key_here/
Best wishes!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!