我有一个需要通过JAXB解析的对象引用,我需要为此编写一个自定义适配器。参考是
Set<List<CustomClass>>
我无法理解如何写出来。有人可以帮我这个吗?
我是
的类文件a)班级档案1
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import com.mypackage.JobServiceDiscountsPOJO;
@XmlRootElement
@XmlAccessorType(value = XmlAccessType.FIELD)
public class MyDiscounts{
private Set<List<JobServiceDiscountsPOJO>> jobServiceDiscountSet;
//constructors
}
b)类文件2
import java.util.*;
@XmlRootElement
@XmlAccessorType(value = XmlAccessType.FIELD)
public class JobServiceDiscountsPOJO{
int discountAmount=0;
//constructors and other methods
}
我需要通过Jersey-API服务返回第1类,即MyDiscounts。
类文件3
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
import javax.ws.rs.POST;
import javax.ws.rs.core.Context;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
@Path("/discount")
public class DiscountService{
@POST
@Produces("application/xml")
@Path("/couponCartValid")
public String getDiscountsXML(){
MyDiscounts discount=new MyDiscounts();
try{
Marshaller jaxbMarshaller =jaxbContext.createMarshaller();
StringWriter writerxmlObj = new StringWriter();
jaxbMarshaller.marshal(order, writerxmlObj);
String xml = String.valueOf(writerxmlObj);
xml = xml.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim();
return xml;
}catch(Exception e){
return e.printStackTrace();
}
}