Java Code Examples for com.thoughtworks.xstream.XStream#autodetectAnnotations()

The following examples show how to use com.thoughtworks.xstream.XStream#autodetectAnnotations() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private <T> T getSpec(URL file) {
    try {
        XStream xstream = new XStream(new DomDriver());
        xstream.autodetectAnnotations(true);
        xstream.processAnnotations(Bit.class);
        xstream.processAnnotations(BitField.class);
        xstream.processAnnotations(Characteristic.class);
        xstream.processAnnotations(Enumeration.class);
        xstream.processAnnotations(Enumerations.class);
        xstream.processAnnotations(Field.class);
        xstream.processAnnotations(InformativeText.class);
        xstream.processAnnotations(Service.class);
        xstream.processAnnotations(Value.class);
        xstream.processAnnotations(Reserved.class);
        xstream.processAnnotations(Examples.class);
        xstream.processAnnotations(CharacteristicAccess.class);
        xstream.processAnnotations(Characteristics.class);
        xstream.processAnnotations(Properties.class);
        xstream.ignoreUnknownElements();
        xstream.setClassLoader(Characteristic.class.getClassLoader());
        return (T) xstream.fromXML(file);
    } catch (Exception e) {
        logger.error("Could not read file: " + file, e);
    }
    return null;
}
 
Example 2
public static HeadResponse headFromXML (final String xml) {
    XStream xStreamInstance = new XStream();
    xStreamInstance.setMode(XStream.NO_REFERENCES);
    xStreamInstance.autodetectAnnotations(false);
    xStreamInstance.alias("response", HeadResponse.class);
    xStreamInstance.alias("row", Row.class);
    xStreamInstance.registerConverter(new AmforeasMapConverter());
    xStreamInstance.addImplicitCollection(HeadResponse.class, "rows", Row.class);
    return (HeadResponse) xStreamInstance.fromXML(xml);
}
 
Example 3
public void marshalForm(FormLayout fs,Writer w) {
    XStream stream = new XStream();

    stream.autodetectAnnotations(true);
    stream.registerConverter(new NumberConverter());

    stream.toXML(fs,w);
}
 
Example 4
Source Project: PoseidonX   File: PhysicalPlanWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 将执行计划序列化成字符串
 */
public static String createStringPlan(PhysicalPlan plan)
{
    XStream xstream = new XStream(new DomDriver(XML_CHARSET));
    xstream.autodetectAnnotations(true);
    PhysicalPlanLoader.setAlias(xstream);
    xstream.registerConverter(new MapConverter(new DefaultMapper(new ClassLoaderReference(PhysicalPlanWriter.class.getClassLoader()))));
    return xstream.toXML(plan);
}
 
Example 5
Source Project: nfse   File: GerarNFSeResposta.java    License: MIT License 5 votes vote down vote up
public static GerarNFSeResposta toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("GerarNfseResposta", GerarNFSeResposta.class);
  xstream.alias("Nfse", NFSe.class);
  GerarNFSeResposta gerarNfseResposta = (GerarNFSeResposta) xstream.fromXML(xml);
  return gerarNfseResposta;
}
 
Example 6
Source Project: nfse   File: AbstractService.java    License: MIT License 5 votes vote down vote up
public String converterParaXml() {
  String XML_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  
  return XML_HEADER + xstream.toXML(this);
}
 
Example 7
Source Project: nfse   File: ConsultarLoteRpsResposta.java    License: MIT License 5 votes vote down vote up
public static ConsultarLoteRpsResposta toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("ConsultarLoteRpsResposta", ConsultarLoteRpsResposta.class);
  xstream.alias("Nfse", Nfse.class);
  ConsultarLoteRpsResposta gerarNfseResposta = (ConsultarLoteRpsResposta) xstream.fromXML(xml);
  return gerarNfseResposta;
}
 
Example 8
Source Project: nfse   File: EnviarLoteRpsResposta.java    License: MIT License 5 votes vote down vote up
public static EnviarLoteRpsResposta toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("EnviarLoteRpsResposta", EnviarLoteRpsResposta.class);
  EnviarLoteRpsResposta enviarLoteRpsResposta = (EnviarLoteRpsResposta) xstream.fromXML(xml);
  return enviarLoteRpsResposta;
}
 
Example 9
Source Project: nfse   File: CompNFSe.java    License: MIT License 5 votes vote down vote up
public static CompNFSe toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("CompNfse", CompNFSe.class);
  xstream.alias("Nfse", NFSe.class);
  CompNFSe compNfse = (CompNFSe) xstream.fromXML(xml);
  return compNfse;
}
 
Example 10
Source Project: aaden-pay   File: XmlBeanJsonConverUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 把XML转成对象
 *
 * @param xmlStr
 * @return Object
 */
@SuppressWarnings("unchecked")
public static <T> T xmlStringToBean(String xmlStr, Class<T> cls) {
	XStream xstream = new XStream(new DomDriver());
	xstream.processAnnotations(cls);
	xstream.autodetectAnnotations(true);
	return (T) xstream.fromXML(xmlStr);
}
 
Example 11
Source Project: aaden-pay   File: XmlBeanJsonConverUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 把XML转成对象
 *
 * @param xmlStr
 * @param clss
 *            是转换对象的所有对象的list列表如aa.class
 * @return Object
 */
@SuppressWarnings("unchecked")
public static <T> T xmlStringToBean(String xmlStr, List<Class<T>> clss) {
	XStream xstream = new XStream(new DomDriver());
	for (Class<T> cls : clss) {
		xstream.processAnnotations(cls);
	}
	xstream.autodetectAnnotations(true);
	return (T) xstream.fromXML(xmlStr);
}
 
Example 12
Source Project: aaden-pay   File: XmlBeanJsonConverUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 把XML转成对象
 *
 * @param <T>
 * @param cls
 * @return Object
 */
@SuppressWarnings("unchecked")
public static <T> T xmlStringToBean(Reader reader, Class<T> cls) {
	XStream xstream = new XStream(new DomDriver());
	xstream.processAnnotations(cls);
	xstream.autodetectAnnotations(true);
	return (T) xstream.fromXML(reader);
}
 
Example 13
Source Project: aaden-pay   File: XmlBeanJsonConverUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 把XML转成对象
 *
 * @param input
 *            InputStream
 * @return Object
 */
@SuppressWarnings("unchecked")
public static <T> T xmlStringToBean(InputStream input, Class<T> cls) {
	XStream xstream = new XStream(new DomDriver());
	xstream.processAnnotations(cls);
	xstream.autodetectAnnotations(true);
	return (T) xstream.fromXML(input);
}
 
Example 14
protected XStream createXStream() {
    XStream xStream = new XStream();
    xStream.setClassLoader(XStreamSessionIO.class.getClassLoader());
    xStream.autodetectAnnotations(true);
    xStream.alias("session", Session.class);
    xStream.alias("configuration", DomElement.class, DefaultDomElement.class);
    return xStream;
}
 
Example 15
public static ErrorResponse errorFromXML (final String xml) {
    XStream xStreamInstance = new XStream();
    xStreamInstance.setMode(XStream.NO_REFERENCES);
    xStreamInstance.autodetectAnnotations(false);
    xStreamInstance.alias("response", ErrorResponse.class);
    return (ErrorResponse) xStreamInstance.fromXML(xml);
}
 
Example 16
Source Project: tutorials   File: XStreamMarshaller.java    License: MIT License 5 votes vote down vote up
public XStreamMarshaller() {
    super();

    xstream = new XStream();
    xstream.autodetectAnnotations(true);
    xstream.processAnnotations(Foo.class);
}
 
Example 17
public static SuccessResponse successFromXML (final String xml) {
    XStream xStreamInstance = new XStream();
    xStreamInstance.setMode(XStream.NO_REFERENCES);
    xStreamInstance.autodetectAnnotations(false);
    xStreamInstance.alias("response", SuccessResponse.class);
    xStreamInstance.alias("row", Row.class);
    xStreamInstance.alias("cells", HashMap.class);
    xStreamInstance.alias("roi", Integer.class);
    xStreamInstance.registerConverter(new AmforeasMapConverter());
    xStreamInstance.addImplicitCollection(SuccessResponse.class, "rows", Row.class);
    return (SuccessResponse) xStreamInstance.fromXML(xml);
}
 
Example 18
public static String success(String msg) {
  WxPayNotifyResponse response = new WxPayNotifyResponse(SUCCESS, msg);
  XStream xstream = XStreamInitializer.getInstance();
  xstream.autodetectAnnotations(true);
  return xstream.toXML(response);
}
 
Example 19
@Bean
public XStream xStream() {
    XStream xstream = new XStream();
    xstream.autodetectAnnotations(true);
    return xstream;
}
 
Example 20
Source Project: brooklyn-server   File: XmlSerializer.java    License: Apache License 2.0 4 votes vote down vote up
public XmlSerializer(ClassLoader loader, Map<String, String> deserializingClassRenames) {
    this.deserializingClassRenames = deserializingClassRenames;
    xstream = new XStream() {
        @Override
        protected MapperWrapper wrapMapper(MapperWrapper next) {
            return XmlSerializer.this.wrapMapperForNormalUsage( super.wrapMapper(next) );
        }
    };

    XStream.setupDefaultSecurity(xstream);
    xstream.allowTypesByWildcard(new String[] {
           "**"
    });

    if (loader!=null) {
        xstream.setClassLoader(loader);
    }
    
    xstream.registerConverter(newCustomJavaClassConverter(), XStream.PRIORITY_NORMAL);
    
    // list as array list is default
    xstream.alias("map", Map.class, LinkedHashMap.class);
    xstream.alias("set", Set.class, LinkedHashSet.class);
    
    xstream.registerConverter(new StringKeyMapConverter(xstream.getMapper()), /* priority */ 10);
    xstream.alias("MutableMap", MutableMap.class);
    xstream.alias("MutableSet", MutableSet.class);
    xstream.alias("MutableList", MutableList.class);
    
    // Needs an explicit MutableSet converter!
    // Without it, the alias for "set" seems to interfere with the MutableSet.map field, so it gets
    // a null field on deserialization.
    xstream.registerConverter(new MutableSetConverter(xstream.getMapper()));
    
    xstream.aliasType("ImmutableList", ImmutableList.class);
    xstream.registerConverter(new ImmutableListConverter(xstream.getMapper()));
    xstream.registerConverter(new ImmutableSetConverter(xstream.getMapper()));
    xstream.registerConverter(new ImmutableMapConverter(xstream.getMapper()));

    xstream.registerConverter(new EnumCaseForgivingConverter());
    xstream.registerConverter(new Inet4AddressConverter());
    
    // See ObjectWithDefaultStringImplConverter (and its usage) for why we want to auto-detect 
    // annotations (usages of this is in the camp project, so we can't just list it statically
    // here unfortunately).
    xstream.autodetectAnnotations(true);
}