Based on the proof xsd and the retail complement I have generated the necessary java classes to fill them. With this code the proof and detailed class is full.
try
{
String cfdi="",complemento_det="";
cFunctions functions=new cFunctions();
ObjectMapper omapper=new ObjectMapper();
Comprobante comprobante=new Comprobante();
Detallista cdetallista=new Detallista();
JSONObject jpreCFDI=new JSONObject(java.net.URLDecoder.decode(preCFDI, "UTF-8"));
List<Object> lst_complemento=new ArrayList();
if(jpreCFDI.has("complemento"))
{
JSONArray complementos=jpreCFDI.getJSONArray("complemento");
jpreCFDI.remove("complemento");
for(int i=complementos.length()-1;i>=0;i--)
{
JSONObject complemento=complementos.getJSONObject(i);
JSONObject any=complemento.getJSONObject("any");
if(any.has("cdetallista"))
{
JSONObject jcdetallista=any.getJSONObject("cdetallista");
cdetallista=omapper.readValue(jcdetallista.toString(),Detallista.class);
lst_complemento.add(cdetallista);
complemento_det="detallista";
}
}
}
comprobante=omapper.readValue(jpreCFDI.toString(),Comprobante.class);
cfdi=functions.getCFDI_string(comprobante,"");
setOriginal_string(functions.getOriginal_String(cfdi,getXlst_path()));
if(getOriginal_string().equals("e-cadena"))
return new JSONObject().put("Code","afe-e05").put("Message","Error al generar cadena original").put("CFDI","");
if(functions.getStamp_CFDI(getPassword_key_file(),getOriginal_string(),getKey_file_path()).equals("e-campos"))
return new JSONObject().put("Code","afe-e06").put("Message","Faltan campos para generar sello digital").put("CFDI","");
else if(functions.getStamp_CFDI(getPassword_key_file(),getOriginal_string(),getKey_file_path()).equals("e-password"))
return new JSONObject().put("Code","afe-e07").put("Message","Contraseña incorrecta de archivo .key").put("CFDI","");
comprobante.setSello(functions.getStamp_CFDI(getPassword_key_file(),getOriginal_string(),getKey_file_path()));
comprobante.setCertificado(functions.getCertificated_CFDI(getCertificated_file_path()));
Complemento complemento=new Complemento();
complemento.getAny().add(lst_complemento);
comprobante.getComplemento().add(complemento);
cfdi=functions.getCFDI_string(comprobante,complemento_det);
return new JSONObject().put("Code","afe-200").put("Message","success").put("CFDI",cfdi);
}
But when I want to generate the string with the xml, I get the following error: (javax.xml.bind.MarshalException) javax.xml.bind.MarshalException - with linked exception: [com.sun.istack.internal.SAXException2: class java.util.ArrayList or any of its superclasses are known in this context. javax.xml.bind.JAXBException: class java.util.ArrayList or any of its superclasses are known in this context.]
and so I generate the string with the xml:
String prefix;
JAXBContext jcontext;
if(complemento.equals("detallista")){
jcontext=JAXBContext.newInstance(new Class[]{Comprobante.class,Detallista.class});
prefix="http://www.sat.gob.mx/detallista http://www.sat.gob.mx/sitio_internet/cfd/detallista/detallista.xsd";
}
/*else if(complemento.equals("donat"))
{
jcontext=JAXBContext.newInstance(new Class[]{Comprobante.class});
}*/
else
{
jcontext=JAXBContext.newInstance(new Class[]{Comprobante.class});
prefix="";
}
String xml="";
Marshaller marsh=jcontext.createMarshaller();
marsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marsh.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marsh.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd "+prefix);
try(StringWriter swriter=new StringWriter()){
marsh.marshal(cfdi,swriter);
xml=swriter.toString();
}
return xml;
How can I solve it?