本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
}
示例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()));
}
示例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>"));
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
示例15: createFactory
import com.fasterxml.jackson.dataformat.xml.XmlFactory; //导入依赖的package包/类
@Override
protected JsonFactory createFactory() {
return new XmlFactory();
}