有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Enounciate的XmlJavaTypeAdapter和JavaXML客户端模块的java问题

  1. 创建了DateFormatterAdapter类并应用于date字段

    @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有一个方法使用Event的对象作为输入

    public class EventService {
    
         public void findEvent(Event  event) {
    
         }
    
    }
    
  3. 此外,我们还在pom中添加了Enounce2.10.1配置以及Java XML客户端模块。xml https://github.com/stoicflame/enunciate/wiki/Module-Java-XML-Client

  4. 我们有一个集成测试类,它正在测试EventService中的findEvent方法。但在添加Enounciate配置后,由于编译错误而失败。在它正常工作之前

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

    但是在运行mvn test之后,我们在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) 个答案