Issue with XmlJavaTypeAdapter AndJava XML Client Module of Enunciate

119 views Asked by At
  1. Created DateFormatterAdapter class and applied to date field

    @XmlAccessorType(XmlAccessType.FIELD)
    public class Event {
        @XmlJavaTypeAdapter(DateFormatterAdapter.class)
        private Date date;
    
        private String description;
    
    
        public Date getDate() {
            return date;
        }
    
        public void setDate(final Date date) {
            this.date = date;
        }
    
    }  
    
    private static class DateFormatterAdapter extends XmlAdapter<String, Date> {
        private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyyy");
    
        @Override
        public Date unmarshal(final String v) throws Exception {
            return dateFormat.parse(v);
        }
    
        @Override
        public String marshal(final Date v) throws Exception {
            return dateFormat.format(v);
        }
    }
    
  2. EventService is having one method which is using an object of Event as input

    public class EventService {
    
         public void findEvent(Event  event) {
    
         }
    
    }
    
  3. Also we added enunciate 2.10.1 configurations along with Java XML Client Module in the pom.xml https://github.com/stoicflame/enunciate/wiki/Module-Java-XML-Client

  4. We have an integration test class which is testing findEvent method in EventService .But fails with compilation error after adding enunciate configurations. Before it was working fine

      @Test
      public void testFindEvent{
          Event event= new Event();
    
          event.setDate(new Date());
    
          EventService  service=new EventService();
          service.findEvent(event);
      }
    

    But after running mvn test, we got Compilation error in event.setDate(new Date());

    method setDate in class Event cannot be applied to given types;
    [ERROR] required: java.lang.String
    [ERROR] found: java.util.Date

0

There are 0 answers