pessoal eu to com um problema q é o seguinte,
tenho atributos opcionais nas minhas classes javas que estão sem valor, e qdo gero um xml, desse objeto, com o xstream esses atributos em branco são colocados no meu xml com o valor igual a “0”.
Como faço pra estes atributos sem valor, não aparecem no meu XML, pois isso está me ocasionando erros?
A minha classe eh essa:
package br.inf.portalfiscal.nfe.model.imposto.ipi;
public class IPITribVO {
protected String CST;
protected double vBC;
protected double vUnid;
get’s e set’
}
este terceiro atributo eh opcional e qdo ele não vem com valor o xml gerado é o seginte:
99
4.62
[color=red] 0.0[/color]
Alguma idéia :?: ![:frowning: :frowning:](//www.guj.com.br/images/emoji/twitter/frowning.png?v=5)
Se você quer que esse atributo não apareça no XML você deve usar um Double ao ivés de double. Não se esqueça que atributos do tipo primitivo double são inicializados com 0.0 e terão este valor se você não especificar um.
Se você quiser que não apareça nada, use o wrapper de Double, que neste seu caso será null e não aparecerá no XML.
pessoal, qdo eu serializo um objeto em XML eu tenho o seguinte erro:
16:22:26,096 ERROR [LogInterceptor] TransactionRolledbackLocalException in method: public abstract void br.inf.portalfiscal.nfe.controller.FilaLocal.finalizarProcessamento(br.inf.portalfiscal.nfe.model.FilaVO)throws br.inf.portalfiscal.nfe.exception.NfeAplicacaoException,br.inf.portalfiscal.nfe.exception.NfeSessionFactoryException,java.lang.Exception,causedBy:
java.lang.NullPointerException
at br.inf.portalfiscal.nfe.converter.XmlnsConverter.toString(XmlnsConverter.java:20)
at com.thoughtworks.xstream.converters.SingleValueConverterWrapper.toString(SingleValueConverterWrapper.java:27)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$1.visit(AbstractReflectionConverter.java:56)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:109)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:49)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:41)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:59)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.marshallField(AnnotationReflectionConverter.java:37)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:105)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:81)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:109)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:41)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:59)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.marshallField(AnnotationReflectionConverter.java:37)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:105)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:81)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:109)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:41)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:59)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.marshallField(AnnotationReflectionConverter.java:37)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:105)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:81)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:109)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:41)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:59)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:73)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.marshal(ReferenceByXPathMarshallingStrategy.java:34)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:745)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:734)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:715)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:705)
eu posso dizer q seria pq o xstream tenta achar um elemento, ou seja um atributo na classe, e não o encontra ?
alguma ideia?