当前位置: 首页>>代码示例>>Java>>正文


Java XmlMapper类代码示例

本文整理汇总了Java中com.fasterxml.jackson.dataformat.xml.XmlMapper的典型用法代码示例。如果您正苦于以下问题:Java XmlMapper类的具体用法?Java XmlMapper怎么用?Java XmlMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XmlMapper类属于com.fasterxml.jackson.dataformat.xml包,在下文中一共展示了XmlMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getXmlMapper

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
protected XmlMapper getXmlMapper() {
    final XmlMapper xmlMapper = new XmlMapper(
            new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
    xmlMapper.setInjectableValues(new InjectableValues.Std().addValue(ODataClient.class, client));
    xmlMapper.addHandler(new DeserializationProblemHandler() {

        @Override
        public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser jp,
                final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName)
                throws IOException, JsonProcessingException {

            // skip any unknown property
            LOG.warn("Skipping unknown property {}", propertyName);
            ctxt.getParser().skipChildren();
            return true;
        }
    });
    return xmlMapper;
}
 
开发者ID:ashank,项目名称:Office-365-SDK-for-Android,代码行数:20,代码来源:AbstractODataDeserializer.java

示例2: getXmlMapper

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
protected XmlMapper getXmlMapper() {
  final XmlMapper xmlMapper = new XmlMapper(
      new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());

  xmlMapper.setInjectableValues(new InjectableValues.Std().addValue(Boolean.class, Boolean.FALSE));

  xmlMapper.addHandler(new DeserializationProblemHandler() {
    @Override
    public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser jp,
        final com.fasterxml.jackson.databind.JsonDeserializer<?> deserializer,
        final Object beanOrClass, final String propertyName)
        throws IOException, JsonProcessingException {

      // skip any unknown property
      ctxt.getParser().skipChildren();
      return true;
    }
  });
  return xmlMapper;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:21,代码来源:ClientODataDeserializerImpl.java

示例3: testParseSiteMap

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
@Test
public void testParseSiteMap() throws Exception {

	InputStream stream = getClass().getClassLoader().getResourceAsStream("xml/footer.xml");
	XmlMapper xmlMapper = new XmlMapper();
	Footer footer = xmlMapper.readValue(stream, Footer.class);
	assertEquals(7, footer.getMenuset().size());
	SiteMap frSiteMap = footer.getMenuset().get(0);
	assertEquals("fr", frSiteMap.getLanguage());
	assertEquals(13, frSiteMap.getEntries().size());
	assertEquals("/fr/association", frSiteMap.getEntries().get(0).getUrl());
	assertEquals("Association", frSiteMap.getEntries().get(0).getLabel());

	SiteMap enSiteMap = footer.getMenuset().get(1);
	assertEquals("en", enSiteMap.getLanguage());
	assertEquals(13, enSiteMap.getEntries().size());
}
 
开发者ID:ozwillo,项目名称:ozwillo-portal,代码行数:18,代码来源:SiteMapFooterParserTest.java

示例4: newInstance

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
/**
 * Creates properly configured Jackson XML Mapper instances.
 * @return XmlMapper instance.
 */
public static XmlMapper newInstance() {
    // Create new mapper
    final JacksonXmlModule module = new JacksonXmlModule();
    module.setDefaultUseWrapper(false);
    XmlMapper mapper = new XmlMapper(module);

    // Configure it
    mapper
        .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
        .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
        .registerModule(new JodaModule())
        .setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

    return mapper;
}
 
开发者ID:Crim,项目名称:pardot-java-client,代码行数:20,代码来源:JacksonFactory.java

示例5: testVXML

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
@Test
public void testVXML(TestContext context) throws Exception{
    final Async async = context.async();
    client.getAbs("http://39.108.96.23/static/test.xmlv")
            .send(ar ->{
                if(ar.succeeded()){
                    System.out.println(ar.result().getHeader("Content-Type"));
                    System.out.println(ar.result().bodyAsString());

                    ObjectMapper xmlMapper = new XmlMapper();
                    try {
                        XmlV xmlV = xmlMapper.readValue(ar.result().bodyAsString(), XmlV.class);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }else{

                }
                async.complete();
            });
}
 
开发者ID:whitewoodcity,项目名称:xbrowser,代码行数:22,代码来源:MyTest.java

示例6: renderWithCustomSerializerLocatedByFactory

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
@Test
public void renderWithCustomSerializerLocatedByFactory() throws Exception {
	SerializerFactory factory = new DelegatingSerializerFactory(null);
	XmlMapper mapper = new XmlMapper();
	mapper.setSerializerFactory(factory);
	view.setObjectMapper(mapper);

	Object bean = new TestBeanSimple();
	Map<String, Object> model = new HashMap<String, Object>();
	model.put("foo", bean);

	view.render(model, request, response);

	String result = response.getContentAsString();
	assertTrue(result.length() > 0);
	assertTrue(result.contains("custom</testBeanSimple>"));

	validateResult();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:MappingJackson2XmlViewTests.java

示例7: getDefaultObjectMapper

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
private ObjectMapper getDefaultObjectMapper(boolean xml, boolean details, TreeNode<String, Boolean> perms) {
    if (perms == null) {
        throw new NullPointerException("Permissions may not be null");
    }

    ObjectMapper om = xml ? new XmlMapper() : new ObjectMapper();
    om.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    SimpleModule mod = new SimpleModule();
    for (Map.Entry<Class, BaseSerializer> entry : serializers.entrySet()) {
        mod.addSerializer(entry.getKey(), entry.getValue());
    }
    mod.addDeserializer(ItemStack.class, new ItemStackDeserializer());
    mod.addDeserializer(BlockState.class, new BlockStateDeserializer());
    mod.addDeserializer(ItemStackSnapshot.class, new ItemStackSnapshotDeserializer());
    mod.addDeserializer(Location.class, new LocationDeserializer());
    om.registerModule(mod);

    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.addFilter(BaseFilter.ID, new BaseFilter(details, perms));
    om.setFilterProvider(filterProvider);

    om.setAnnotationIntrospector(new AnnotationIntrospector(details));

    return om;
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:27,代码来源:SerializeService.java

示例8: adaptXMLLine

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
private ObjectNode adaptXMLLine(String line)
{
  XmlMapper mapper = new XmlMapper();
  ObjectNode objNode = null;
  try
  {
    objNode = mapper.readValue(line, ObjectNode.class);
    objNode.put("_id", objNode.get("Id").asText());
    objNode.remove("Id");
  } catch (Exception e)
  {
    e.printStackTrace();
  }

  return objNode;
}
 
开发者ID:catedrasaes-umu,项目名称:NoSQLDataEngineering,代码行数:17,代码来源:SOF2Db.java

示例9: deserializationXMLContextAttribute

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
@Test
public void deserializationXMLContextAttribute() throws IOException {

    String xml =
            "        <contextAttribute>\n" +
                    "        <name>A</name>\n" +
                    "        <type>T</type>\n" +
                    "        <contextValue>22</contextValue>\n" +
                    "        </contextAttribute>\n";

    ObjectMapper xmlmapper = new XmlMapper();
    ContextAttribute contextAttribute = xmlmapper.readValue(xml, ContextAttribute.class);
    assertEquals("A", contextAttribute.getName());
    assertEquals("T", contextAttribute.getType());
    assertEquals("22", contextAttribute.getValue());
}
 
开发者ID:Orange-OpenSource,项目名称:fiware-ngsi-api,代码行数:17,代码来源:ContextAttributeModelTest.java

示例10: serializationXMLContextAttribute

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
@Test
public void serializationXMLContextAttribute() throws IOException, XPathExpressionException {

    ContextAttribute contextAttribute = new ContextAttribute("A", "T", "22");

    ObjectMapper xmlmapper = new XmlMapper();
    String xml = xmlmapper.writeValueAsString(contextAttribute);

    assertTrue(xml.contains("A"));
    assertTrue(xml.contains("T"));
    assertTrue(xml.contains("22"));

    String xpathExpr = "/ContextAttribute/name";
    XPath xPath = XPathFactory.newInstance().newXPath();
    assertEquals("A", xPath.evaluate(xpathExpr, new InputSource(new StringReader(xml))));
}
 
开发者ID:Orange-OpenSource,项目名称:fiware-ngsi-api,代码行数:17,代码来源:ContextAttributeModelTest.java

示例11: generatePayNativeReplyXML

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
public static String generatePayNativeReplyXML(PayPackage payPackage){
	try {
		
		Map<String, String> map = BeanUtils.describe(payPackage);
		map.remove("class");
		
		String sign = Signature.generateSign(map);
		payPackage.setSign(sign);
		
		XmlMapper xmlMapper = new XmlMapper();
		xmlMapper.setSerializationInclusion(Include.NON_EMPTY);
		
		String xmlContent = xmlMapper.writeValueAsString(payPackage);
		
		HttpsRequest httpsRequest = new HttpsRequest();
		String result = httpsRequest.sendPost(Configure.UNIFY_PAY_API, xmlContent);
		return result;
	} catch (Exception e) {
		logger.info("e:" + e);
	}
	
	return null;
}
 
开发者ID:louiseliu,项目名称:weixin-pay,代码行数:24,代码来源:PayUtils.java

示例12: testBinding

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
@Test
public void testBinding(){
    XmlMapper xmlMapper = new XmlMapper();
    try {
        //String xml = xmlMapper.writerWithDefaultPrettyPrinter().writeValueAsString(new ORNEvent("operation name","rowid"));
        TableQrns tableQrns = new TableQrns(1, "tablename", new ArrayList<QRNEvent>(){{add(new QRNEvent("a","b")); add(new QRNEvent("c","d"));
                }} );

        String xml = xmlMapper.writerWithDefaultPrettyPrinter().writeValueAsString(tableQrns);
        Assert.assertNotNull(xml);
        System.out.println(xml);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }

}
 
开发者ID:srecon,项目名称:OracleToElasticSearch,代码行数:17,代码来源:XMLBindingTest.java

示例13: testDeserialization

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
@Test
public void testDeserialization() throws Exception{
    ObjectMapper objectMapper = new XmlMapper();
    TableQrns tableQrns = objectMapper.readValue("<TableQrns>\n" +
            "  <objectId>11</objectId>\n" +
            "  <tableName>tablenameTest</tableName>\n" +
            "  <qrnEvents>\n" +
            "    <qrnEvent>\n" +
            "      <operationName>a1</operationName>\n" +
            "      <rowId>b1</rowId>\n" +
            "    </qrnEvent>\n" +
            "    <qrnEvent>\n" +
            "      <operationName>c1</operationName>\n" +
            "      <rowId>d1</rowId>\n" +
            "    </qrnEvent>\n" +
            "  </qrnEvents>\n" +
            "</TableQrns>", TableQrns.class);
    Assert.assertNotNull(tableQrns.getObjectId());
    Assert.assertEquals("array size:",2, tableQrns.getQrnEvent().size());
}
 
开发者ID:srecon,项目名称:OracleToElasticSearch,代码行数:21,代码来源:XMLBindingTest.java

示例14: exportStream

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
@Override
public void exportStream(OutputStream outputStream, Iterator<T> iterator) throws IOException, ClassNotFoundException, IllegalAccessException {
    JacksonXmlModule module = new JacksonXmlModule();
    module.setDefaultUseWrapper(false);
    XmlMapper xmlMapper = new XmlMapper(module);
    XmlFactory factory = new XmlFactory();
    ToXmlGenerator generator = factory.createGenerator(outputStream);

    generator.setCodec(xmlMapper);
    generator.writeRaw("<xml>");

    while (iterator.hasNext()) {

        generator.writeRaw(xmlMapper.writeValueAsString(iterator.next()));
    }
    generator.writeRaw("</xml>");

    generator.flush();
}
 
开发者ID:robeio,项目名称:robe,代码行数:20,代码来源:XMLExporter.java

示例15: createXmlMapper

import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入依赖的package包/类
private static XmlMapper createXmlMapper() {
	return new Jackson2ObjectMapperBuilder()
			// mixins
			.mixIn(Slideshow.class, SlideshowMixIn.class)
			.mixIn(Slideshow.Tag.class, SlideshowMixIn.TagMixin.class)
			.mixIn(Slideshow.RelatedSlideshow.class, SlideshowMixIn.RelatedSlideshowMixin.class)

			.mixIn(GetSlideshowsResponse.class, GetSlideshowsResponseMixin.class)
			.mixIn(SearchSlideshowsResponse.class, SearchSlideshowsResponseMixin.class)
			.mixIn(SearchSlideshowsResponse.MetaInfo.class, SearchSlideshowsResponseMixin.MetaInfoMixin.class)
			.mixIn(SlideshowIdHolder.class, SlideshowIdHolderMixin.class)

			// errors
			.mixIn(SlideShareServiceError.class, SlideShareServiceErrorMixin.class)
			.mixIn(SlideShareServiceError.Message.class, SlideShareServiceErrorMixin.MessageMixin.class)

			.dateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz"))
			.createXmlMapper(true)
			.build();
}
 
开发者ID:ttddyy,项目名称:spring-social-slideshare,代码行数:21,代码来源:JacksonUtils.java


注:本文中的com.fasterxml.jackson.dataformat.xml.XmlMapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。