JUnit 测试中的 IllegalAnnotationExceptions

我想创建 JUnit 测试来测试 JAXB 代码:


@XmlRootElement(name = "reconcile")

public class Reconcile {


    @XmlElement(name = "start_date")

    @XmlJavaTypeAdapter(LocalDateTimeXmlAdapter.class)

    public LocalDateTime start_date;

    @XmlElement(name = "end_date")

    @XmlJavaTypeAdapter(LocalDateTimeXmlAdapter.class)

    public LocalDateTime end_date;

    @XmlElement(name = "page")

    public String page;


    //// getters and setters

}

我为上面的代码尝试了这个 JUnit 测试:


import java.time.LocalDateTime;


import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBException;

import javax.xml.bind.Marshaller;


import org.datalis.plugin.reconcile.Reconcile;

import org.junit.jupiter.api.Test;


public class ReconciliationTest {


    @Test

    public void uniqueTransactionIdLenght() throws JAXBException {


        Reconcile reconcile = new Reconcile();

        reconcile.start_date = LocalDateTime.of(2018, 4, 8, 11, 2, 44);

        reconcile.end_date = LocalDateTime.of(2018, 11, 8, 11, 2, 44);

        reconcile.page = "1";


        JAXBContext jaxbContext = JAXBContext.newInstance(Reconcile.class);

        Marshaller marshaller = jaxbContext.createMarshaller();

        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        marshaller.marshal(reconcile, System.out);

    }

}

但是当我运行代码时,我得到:


com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions

    at org.datalis.plugin.jaxb.ReconciliationTest.uniqueTransactionIdLenght(ReconciliationTest.java:22)

在这一行


JAXBContext jaxbContext = JAXBContext.newInstance(Reconcile.class);

有没有办法解决这个问题?


UYOU
浏览 177回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java