JAX-RS @DefaultValue Annotation Restful Example in Java

In this tutorial we see what is the use of @DefaultValue in JAX – RS. @DefaultValue annotation is used to set the default values  and make them available to java method to in our java service class.

Let us have a example how to implement  @DefaultValue annotation in JAX-RS

1. Create Dynamic web project in Eclipse.

RestfulDefaultValueAnnotationExample_proj

2. Write Java service class.

 

3. Configure the Jersey Container in web.xml

 

4. Run the Example

NOTE : I have not included all the required jersey jars in the source code please download it from here and copy to lib folder.

 

http://localhost:8080/RestfulDefaultValueAnnotationExample/rest/register/add?firstname=Ramesh&email=test@gmail.com&lastname=Tatipigari

 

In the above url we are passing some parameters, in this case @DefaultValue annotation will not consider default values. so the param values what ever we are passing those values only consider.

RestfulDefaultValueAnnotationExample_1

http://localhost:8080/RestfulDefaultValueAnnotationExample/rest/register/add

 

In the above url we are not passing any parameters, in this case @DefaultValue annotation will consider default values which are we set in service class method.

RestfulDefaultValueAnnotationExample_2

 

 

Download  Source Code

 

 

 

Posted in webservices and tagged , , .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">