本文整理汇总了Java中org.springframework.oxm.xstream.XStreamMarshaller类的典型用法代码示例。如果您正苦于以下问题:Java XStreamMarshaller类的具体用法?Java XStreamMarshaller怎么用?Java XStreamMarshaller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XStreamMarshaller类属于org.springframework.oxm.xstream包,在下文中一共展示了XStreamMarshaller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessageConverter
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
/**
* @param xstreamMarshaller The fully configured {@link XStreamMarshaller}
* @return The configured {@link MarshallingHttpMessageConverter}.
*/
@Bean
public MarshallingHttpMessageConverter getMessageConverter(
final XStreamMarshaller xstreamMarshaller) {
final List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_XML);
mediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
final MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter();
xmlConverter.setSupportedMediaTypes(mediaTypes);
xmlConverter.setMarshaller(xstreamMarshaller);
xmlConverter.setUnmarshaller(xstreamMarshaller);
return xmlConverter;
}
示例2: setUp
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
/**
* @throws Exception
*/
@Before
public void setUp() throws Exception {
writer = new StaxEventItemWriter();
writer.setResource(new FileSystemResource("target/test-outputs/StaxWriterTest.xml"));
writer.setRootTagName("urlset");
XStreamMarshaller marshaller = new XStreamMarshaller();
Map<String, Object> aliases = new HashMap<String, Object>();
aliases.put("url", Url.class);
marshaller.setAliases(aliases);
writer.setMarshaller(marshaller);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("xmlns", "http://www.sitemaps.org/schemas/sitemap");
writer.setRootElementAttributes(attributes);
}
示例3: unmarshallTest
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
/**
* Unmarshall test.
*
* @throws Exception
* the exception
*/
@Test
public void unmarshallTest() throws Exception {
final String content = "abcdefg";
final String xmlContent = "<string>" + content + "</string>";
File temp;
temp = File.createTempFile("UnmarshallXmlTestTempFile", ".xml");
final BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
bw.write(xmlContent);
bw.close();
final XStream xstream = new XStream();
xstream.alias("TestXml", TestXml.class);
assertEquals(content, unmarshallXml(new XStreamMarshaller(), temp.getPath()));
}
示例4: configureMessageConverters
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FilteringJackson2HttpMessageConverter jsonConverter
= new FilteringJackson2HttpMessageConverter();
jsonConverter.setSupportedMediaTypes(ApiMediaTypes.getJsonMediaTypes());
converters.add(jsonConverter);
MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter();
xmlConverter.setSupportedMediaTypes(ApiMediaTypes.getXmlMediaTypes());
XStreamMarshaller xStreamMarshaller = new XStreamMarshaller();
xmlConverter.setMarshaller(xStreamMarshaller);
xmlConverter.setUnmarshaller(xStreamMarshaller);
converters.add(xmlConverter);
FilteringTextMessageConverter filteringTextMessageConverter =
new FilteringTextMessageConverter(new MediaType("text", "plain", Charset.forName("utf-8")));
filteringTextMessageConverter.setDelimiter("\t");
converters.add(filteringTextMessageConverter);
}
示例5: registerXStreamMarshaller
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
public void registerXStreamMarshaller(XStreamMarshaller marshaller, ResourceRegister register) throws Exception {
marshaller.setSupportedClasses(register.getTargetClasses());
if (!register.isEmpty()) {
Collection<ClassDescriptor> cls = register.getClassDescriptors();
Map<String, Class<?>> aliases = new HashMap<String, Class<?>>();
Map<Class<?>, String> omittedFields = new HashMap<Class<?>, String>();
for (ClassDescriptor cl : cls) {
Class<?> clazz = cl.getTargetClass();
String name = cl.getName();
if (!StringUtils.hasLength(name))
name = clazz.getSimpleName();
aliases.put(name, clazz);
Collection<String> fields = cl.getExcludesFields();
for (String fieldName : fields) {
omittedFields.put(clazz, fieldName);
}
}
marshaller.setOmittedFields(omittedFields);
marshaller.setAliases(aliases);
}
}
示例6: registerConverter
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
public void registerConverter(Class<? extends ConverterMatcher>... converterClass) throws Exception {
XStreamMarshaller marshaller = (XStreamMarshaller) getMarshaller();
marshaller.setConverters(new ConverterMatcher[] {});
if (converterClass == null) {
return;
}
List<ConverterMatcher> converters = new ArrayList<ConverterMatcher>(converterClass.length);
for (Class<? extends ConverterMatcher> clazz : converterClass) {
if (clazz == null)
continue;
ConverterMatcher converter = clazz.getConstructor(Mapper.class).newInstance(marshaller.getXStream().getMapper());
converters.add(converter);
}
marshaller.setConverters(converters.toArray(new ConverterMatcher[converters.size()]));
}
示例7: getXStreamMarshaller
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
/**
* @return The pre-configured {@link XStreamMarshaller}.
*/
@Bean
public XStreamMarshaller getXStreamMarshaller() {
final XStreamMarshaller xstreamMarshaller = new XStreamMarshaller();
xstreamMarshaller.setSupportedClasses(Bucket.class,
Owner.class,
ListAllMyBucketsResult.class,
CopyPartResult.class,
CopyObjectResult.class,
ListBucketResult.class,
InitiateMultipartUploadResult.class,
ListMultipartUploadsResult.class,
ListPartsResult.class,
CompleteMultipartUploadResult.class,
BatchDeleteRequest.class,
BatchDeleteResponse.class,
ErrorResponse.class);
xstreamMarshaller.setAnnotatedClasses(Bucket.class,
Owner.class,
CopyPartResult.class,
ListAllMyBucketsResult.class,
CopyObjectResult.class,
ListBucketResult.class,
InitiateMultipartUploadResult.class,
ListMultipartUploadsResult.class,
ListPartsResult.class,
CompleteMultipartUploadResult.class,
BatchDeleteRequest.class,
BatchDeleteResponse.class,
ErrorResponse.class);
return xstreamMarshaller;
}
示例8: getMarshallingXmlViewResolver
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
@Bean
public CustomXMLViewResolver getMarshallingXmlViewResolver() { // Resolver para o formato XML
//Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
//marshaller.setClassesToBeBound(Product.class);
XStreamMarshaller marshaller = new XStreamMarshaller();
HashMap<String, Class<?>> keys = new HashMap<String,Class<?>>();
//keys.put("product", Product.class);
//keys.put("price", Price.class);
marshaller.setAliases(keys);
return new CustomXMLViewResolver(marshaller);
}
示例9: createXmlHttpMessageConverter
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
private HttpMessageConverter<Object> createXmlHttpMessageConverter() {
MarshallingHttpMessageConverter xmlConverter =
new MarshallingHttpMessageConverter();
XStreamMarshaller xstreamMarshaller = new XStreamMarshaller();
xmlConverter.setMarshaller(xstreamMarshaller);
xmlConverter.setUnmarshaller(xstreamMarshaller);
return xmlConverter;
}
示例10: createXmlHttpMessageConverter
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
private HttpMessageConverter<Object> createXmlHttpMessageConverter() {
MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter();
XStreamMarshaller xstreamMarshaller = new XStreamMarshaller();
xmlConverter.setMarshaller(xstreamMarshaller);
xmlConverter.setUnmarshaller(xstreamMarshaller);
return xmlConverter;
}
示例11: setUp
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
/**
* @throws Exception
* if there is a problem initializing the unmarshaller
*/
@Before
public final void setUp() throws Exception {
QNameMapFactory qNameMapFactory = new QNameMapFactory();
qNameMapFactory.afterPropertiesSet();
ReflectionProviderFactory reflectionProviderFactory = new ReflectionProviderFactory();
reflectionProviderFactory.afterPropertiesSet();
StaxDriver streamDriver = new StaxDriver(qNameMapFactory.getObject());
streamDriver.setRepairingNamespace(false);
unmarshaller = new XStreamMarshaller();
((XStreamMarshaller) unmarshaller).setAutodetectAnnotations(true);
Map<String, Class<?>> aliases = new HashMap<String, Class<?>>();
aliases.put("Representation", Representation.class);
aliases.put("Agent", Agent.class);
aliases.put("TaxonName", TaxonName.class);
aliases.put("CategoricalCharacter", CategoricalCharacter.class);
aliases.put("StateDefinition", StateDefinition.class);
aliases.put("Dataset", Dataset.class);
((XStreamMarshaller) unmarshaller).setAliases(aliases);
((XStreamMarshaller) unmarshaller).setStreamDriver(streamDriver);
((XStreamMarshaller) unmarshaller)
.setConverters(new ConverterMatcher[] { new URIConverter(), new IgnoreConverter() });
((XStreamMarshaller) unmarshaller).afterPropertiesSet();
}
示例12: createMarshaller
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
/**
* Creates an XStream object based on a media type. By default, it creates a
* {@link HierarchicalStreamDriver} or a {@link DomDriver}.
* @return The XStream object.
*/
protected AbstractMarshaller createMarshaller() {
AbstractMarshaller result = null;
try {
XStreamMarshaller marshaller = new XStreamMarshaller();
marshaller.setStreamDriver(getXmlDriverClass().newInstance());
result = marshaller;
} catch (Exception e) {
Context.getCurrentLogger().log(Level.WARNING, "Unable to create the XStream driver.", e);
}
return result;
}
示例13: productMarshaller
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
@Bean
public XStreamMarshaller productMarshaller() {
HashMap<String, Class> aliases = new HashMap<String, Class>();
aliases.put("product", Product.class);
XStreamMarshaller marshaller = new XStreamMarshaller();
try {
marshaller.setAliases(aliases);
} catch (Exception ignored) {}
return marshaller;
}
示例14: setMarshaller
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
@Autowired(required=false)
public void setMarshaller(XStreamMarshaller marshaller) {
super.setMarshaller(marshaller);
}
示例15: springfieldXStreamMarshaller
import org.springframework.oxm.xstream.XStreamMarshaller; //导入依赖的package包/类
@Bean
public XStreamMarshaller springfieldXStreamMarshaller(){
XStreamMarshaller b = new XStreamMarshaller();
b.setAutodetectAnnotations(true);
return b;
}