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

The following examples show how to use com.thoughtworks.xstream.XStream#autodetectAnnotations() . 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
Source File: BluetoothGattSpecificationReader.java    From bluetooth-gatt-parser with Apache License 2.0 6 votes vote down vote up
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
Source File: XmlBeanJsonConverUtil.java    From aaden-pay with 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 3
Source File: XmlXstreamTest.java    From amforeas with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: XStreamMarshaller.java    From tutorials with MIT License 5 votes vote down vote up
public XStreamMarshaller() {
    super();

    xstream = new XStream();
    xstream.autodetectAnnotations(true);
    xstream.processAnnotations(Foo.class);
}
 
Example 5
Source File: XmlXstreamTest.java    From amforeas with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: XStreamSessionIO.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: XmlBeanJsonConverUtil.java    From aaden-pay with 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 8
Source File: XmlBeanJsonConverUtil.java    From aaden-pay with 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 9
Source File: XmlBeanJsonConverUtil.java    From aaden-pay with 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 10
Source File: XmlXstreamTest.java    From amforeas with GNU General Public License v3.0 5 votes vote down vote up
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 11
Source File: CompNFSe.java    From nfse with 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 12
Source File: EnviarLoteRpsResposta.java    From nfse with 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 13
Source File: ConsultarLoteRpsResposta.java    From nfse with 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 14
Source File: AbstractService.java    From nfse with 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 15
Source File: GerarNFSeResposta.java    From nfse with 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 16
Source File: PhysicalPlanWriter.java    From PoseidonX with 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 17
Source File: FormUtils.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
public void marshalForm(FormLayout fs,Writer w) {
    XStream stream = new XStream();

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

    stream.toXML(fs,w);
}
 
Example 18
Source File: XmlSerializer.java    From brooklyn-server with 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);
}
 
Example 19
Source File: XStreamConfig.java    From Pixiv-Illustration-Collection-Backend with Apache License 2.0 4 votes vote down vote up
@Bean
public XStream xStream() {
    XStream xstream = new XStream();
    xstream.autodetectAnnotations(true);
    return xstream;
}
 
Example 20
Source File: WxPayNotifyResponse.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public static String success(String msg) {
  WxPayNotifyResponse response = new WxPayNotifyResponse(SUCCESS, msg);
  XStream xstream = XStreamInitializer.getInstance();
  xstream.autodetectAnnotations(true);
  return xstream.toXML(response);
}