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


Java XmlFactory类代码示例

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


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

示例1: getXmlMapper

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的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.XmlFactory; //导入依赖的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: exportStream

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的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

示例4: newXMLMapper

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
/**
 * Creates a new {@link com.fasterxml.jackson.dataformat.xml.XmlMapper} using Woodstox
 * with Logback and Joda Time support.
 * Also includes all {@link io.dropwizard.jackson.Discoverable} interface implementations.
 *
 * @return XmlMapper
 */
public static XmlMapper newXMLMapper(JacksonXmlModule jacksonXmlModule) {

    final XmlFactory woodstoxFactory = new XmlFactory(new WstxInputFactory(), new WstxOutputFactory());
    final XmlMapper mapper = new XmlMapper(woodstoxFactory, jacksonXmlModule);

    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new LogbackModule());
    mapper.registerModule(new GuavaExtrasModule());
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new FuzzyEnumModule());
    mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
    mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());

    return mapper;
}
 
开发者ID:yunspace,项目名称:dropwizard-xml,代码行数:23,代码来源:JacksonXML.java

示例5: toMetadata

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
public static Edmx toMetadata(final InputStream input) {
    try {
        final XmlMapper xmlMapper = new XmlMapper(
                new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
        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 {

                // 1. special handling of AbstractAnnotatedEdm's fields
                if (beanOrClass instanceof AbstractAnnotatedEdm
                        && AbstractAnnotatedEdmUtils.isAbstractAnnotatedProperty(propertyName)) {

                    AbstractAnnotatedEdmUtils.parseAnnotatedEdm((AbstractAnnotatedEdm) beanOrClass, jp);
                } // 2. skip any other unknown property
                else {
                    ctxt.getParser().skipChildren();
                }

                return true;
            }
        });
        return xmlMapper.readValue(input, Edmx.class);
    } catch (Exception e) {
        throw new IllegalArgumentException("Could not parse as Edmx document", e);
    }
}
 
开发者ID:mkostin,项目名称:ODataJClient,代码行数:30,代码来源:Deserializer.java

示例6: defaultObjectMapper

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
public static ObjectMapper defaultObjectMapper() {
    return new XmlMapper(new XmlFactory(new WstxInputFactory(), new WstxPrefixedOutputFactory()))
            .enable(SerializationFeature.INDENT_OUTPUT)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
            .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)
            .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
            .registerModule(new ParserModule())
            .setAnnotationIntrospector(AnnotationIntrospector.pair(
                    new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()),
                    new JacksonAnnotationIntrospector()));
}
 
开发者ID:carlanton,项目名称:mpd-tools,代码行数:13,代码来源:MPDParser.java

示例7: serialize_GivesXmlResult_WhenQueryGivesData

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
@Test
public void serialize_GivesXmlResult_WhenQueryGivesData() throws IOException {
  // Arrange
  BindingSet bindingSet = new ListBindingSet(
      ImmutableList.of("identifier", "name", "yearOfFoundation", "craftMember", "fte"),
      DBEERPEDIA.BROUWTOREN, DBEERPEDIA.BROUWTOREN_NAME, DBEERPEDIA.BROUWTOREN_YEAR_OF_FOUNDATION,
      DBEERPEDIA.BROUWTOREN_CRAFT_MEMBER, DBEERPEDIA.BROUWTOREN_FTE);
  when(tupleQueryResult.hasNext()).thenReturn(true, false);
  when(tupleQueryResult.next()).thenReturn(bindingSet);

  XmlFactory factory = new XmlFactory();
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  ToXmlGenerator generator = factory.createGenerator(outputStream);

  // Act
  serializer.serialize(tupleQueryResult, generator, null);


  // Assert
  generator.close();
  assertThat(outputStream.toString(), containsString("<results>"));
  assertThat(outputStream.toString(), containsString(
      String.format("<identifier>%s</identifier>", DBEERPEDIA.BROUWTOREN.toString())));
  assertThat(outputStream.toString(), containsString("<name>Brouwtoren</name>"));
  assertThat(outputStream.toString(), containsString("<fte>1.8</fte>"));
  assertThat(outputStream.toString(), containsString("<craftMember>true</craftMember>"));
  assertThat(outputStream.toString(),
      containsString("<yearOfFoundation>2014</yearOfFoundation>"));
  assertThat(outputStream.toString(), containsString("</results>"));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:31,代码来源:TupleQueryResultXmlSerializerTest.java

示例8: createDefaultMapper

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
public static XmlMapper createDefaultMapper() {
    XmlFactory f = new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl());
    
    XmlMapper mapper = new XmlMapper(f);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
    return mapper;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:12,代码来源:XmlObjectTask.java

示例9: importStream

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
@Override
public void importStream(InputStream inputStream, OnItemHandler handler, String charSetName) throws Exception {

    XmlFactory factory = new XmlFactory();
    JsonParser parser = factory.createParser(new InputStreamReader(inputStream, charSetName));

    Map<String, Field> fields = getFieldMap(getDataClass());

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        try {
            parser.getCurrentName();
        } catch (Exception e) {
            continue;
        }
        if (getDataClass().getSimpleName().equals(parser.getValueAsString())) {
            T item = (T) getDataClass().newInstance();
            while (parser.nextToken() != JsonToken.END_OBJECT) {
                if (parser.getValueAsString() == null || parser.getCurrentToken() == JsonToken.FIELD_NAME)
                    continue;
                Field field = fields.get(parser.getCurrentName());
                setField(parser, item, field);
            }
            handler.onItem(item);
        }

    }

}
 
开发者ID:robeio,项目名称:robe,代码行数:29,代码来源:XMLImporter.java

示例10: getParser

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
public static JsonParser getParser(String xml) throws Exception {
    XmlFactory factory = new XmlFactory();
    JsonParser parser = factory.createParser(xml);
    parser.nextToken();
    parser.nextToken();
    parser.nextToken();
    return parser;
}
 
开发者ID:robeio,项目名称:robe,代码行数:9,代码来源:ParserUtil.java

示例11: toODataErrorFromXML

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
protected XMLODataError toODataErrorFromXML(final InputStream input) {
    try {
        final XmlMapper xmlMapper = new XmlMapper(
                new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
        return xmlMapper.readValue(input, XMLODataError.class);
    } catch (Exception e) {
        throw new IllegalArgumentException("While deserializing XML error", e);
    }
}
 
开发者ID:ashank,项目名称:Office-365-SDK-for-Android,代码行数:10,代码来源:AbstractODataDeserializer.java

示例12: toServiceDocument

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
public ResWrap<ServiceDocument> toServiceDocument(InputStream input) throws ODataDeserializerException {
  try {
    JsonParser parser = new XmlFactory().createParser(input);
    return doDeserialize(parser);
  } catch (final IOException e) {
    throw new ODataDeserializerException(e);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:9,代码来源:XMLServiceDocumentDeserializer.java

示例13: initJsonParser

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
private void initJsonParser() throws IOException {
	if (jsonParser == null) {
		jsonParser = new XmlFactory().createParser(sourceUrl);
		if (jsonParser.nextToken() != JsonToken.START_OBJECT) throw new IllegalStateException("xml should start with an object");
		jsonParser.nextToken();
		jsonParser.nextToken();
	}
}
 
开发者ID:jvalue,项目名称:open-data-service,代码行数:9,代码来源:XmlSourceAdapter.java

示例14: toODataErrorFromXML

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
private static XMLODataError toODataErrorFromXML(final InputStream input) {
    try {
        final XmlMapper xmlMapper = new XmlMapper(
                new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
        return xmlMapper.readValue(input, XMLODataError.class);
    } catch (Exception e) {
        throw new IllegalArgumentException("While deserializing XML error", e);
    }
}
 
开发者ID:mkostin,项目名称:ODataJClient,代码行数:10,代码来源:Deserializer.java

示例15: createFactory

import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
@Override
protected JsonFactory createFactory() {
  return new XmlFactory();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:5,代码来源:XmlTupleEntityWriter.java


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