0 Replies Latest reply on May 10, 2012 10:02 AM by superdev

    JAX-RS and CDI / @Provider  and  beans.xml


      I made a simple project that make use of JAX-RS (RESTfull service)


      I have a JAX-RS (RESTfull service) webservice project that deploys to JBoss 6.1. resteasy integrated with JSON is provided by JBoss 6.1 by default.  I wanted to change the date format of default JSON resource.

      I got some help from the Internet and added a class extends JacksonJsonProvider:





      public class MyJacksonJsonProvider extends JacksonJsonProvider {
            public static final String pattern = "YYYY-MM-dd'T'HH:mm:ss";
            public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
              ObjectMapper mapper = locateMapper(type, mediaType);
              // Set customized date format
              SimpleDateFormat sdf = new SimpleDateFormat(pattern);
              super.writeTo(value, type, genericType, annotations, mediaType, httpHeaders, entityStream);




      This works well until I added an empty beans.xml under WebContent/WEB-INF for CDI injection.


      MyJacksonJsonProvider won't call, I still get default JSON date format.


      Even I added the following dependency under pom.xml did not help.





      Does anyone have any idea why "MyJacksonJsonProvider" will be ingnored if I have an empty beans.xml under "WebContent/WEB-INF" folder? Thanks a lot in advance!



      FYI, this is the sample model class:


      @XmlRootElement(name = "movie")
      public class Movie {
          String name;
          String director;
          int year;
          Date date;
          public String getName() {
              return name;
          public void setName(String name) {
              this.name = name;
          public String getDirector() {
              return director;
          public void setDirector(String director) {
              this.director = director;
          public int getYear() {
              return year;
          public void setYear(int year) {
              this.year = year;
          public Date getDate() {
              return date;
          public void setDate(Date date) {
              this.date = date;


      And this is the class that produces JSON resource:


      public class JSONService {
          public Movie getMovieInJSON() {
              Movie movie = new Movie();
              movie.setName("Little flower");
              movie.setDirector("Zhang Zheng");
              movie.setDate(new Date());
              return movie;