com.fasterxml.jackson.dataformat.xml.JacksonXmlModule Java Examples

The following examples show how to use com.fasterxml.jackson.dataformat.xml.JacksonXmlModule. 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: JacksonFactory.java    From pardot-java-client with MIT License 6 votes vote down vote up
/**
 * Creates properly configured Jackson XML Mapper instances.
 * @return XmlMapper instance.
 */
public static XmlMapper newInstance() {
    if (instance != null) {
        return instance;
    }

    // Create new mapper
    final JacksonXmlModule module = new JacksonXmlModule();
    module.setDefaultUseWrapper(false);
    module.addDeserializer(ProspectCustomFieldValue.class, new ProspectCustomFieldDeserializer());

    final 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;
}
 
Example #2
Source File: XMLExporter.java    From robe with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example #3
Source File: ClientODataDeserializerImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: Jackson2ObjectMapperBuilder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public ObjectMapper create(boolean defaultUseWrapper, @Nullable JsonFactory factory) {
	JacksonXmlModule module = new JacksonXmlModule();
	module.setDefaultUseWrapper(defaultUseWrapper);
	if (factory != null) {
		return new XmlMapper((XmlFactory) factory, module);
	}
	else {
		return new XmlMapper(new XmlFactory(StaxUtils.createDefensiveInputFactory()), module);
	}
}
 
Example #5
Source File: SysomosXmlSerDeIT.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * before.
 */
@BeforeClass
public void before() {

  XmlFactory xmlFactory = new XmlFactory(new InputFactoryImpl(),
      new OutputFactoryImpl());

  JacksonXmlModule module = new JacksonXmlModule();

  module.setDefaultUseWrapper(false);

  xmlMapper = new XmlMapper(xmlFactory, module);

  xmlMapper
      .configure(
          DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
          Boolean.TRUE);
  xmlMapper
      .configure(
          DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
          Boolean.TRUE);
  xmlMapper
      .configure(
          DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY,
          Boolean.TRUE);
  xmlMapper.configure(
      DeserializationFeature.READ_ENUMS_USING_TO_STRING,
      Boolean.TRUE);

}
 
Example #6
Source File: JacksonXML.java    From dropwizard-xml with Apache License 2.0 5 votes vote down vote up
/**
 * 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 GuavaExtrasModule());
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new FuzzyEnumModule());
    mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
    mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());

    return mapper;
}
 
Example #7
Source File: JacksonXmlEngine.java    From pippo with Apache License 2.0 5 votes vote down vote up
@Override
protected ObjectMapper getObjectMapper() {
    // Check out: https://github.com/FasterXML/jackson-dataformat-xml
    JacksonXmlModule module = new JacksonXmlModule();
    // setDefaultUseWrapper produces more similar output to
    // the Json output. You can change that with annotations in your
    // models.
    module.setDefaultUseWrapper(false);
    return new XmlMapper(module);
}
 
Example #8
Source File: Jackson2ObjectMapperBuilder.java    From java-technology-stack with MIT License 4 votes vote down vote up
public ObjectMapper create(boolean defaultUseWrapper) {
	JacksonXmlModule module = new JacksonXmlModule();
	module.setDefaultUseWrapper(defaultUseWrapper);
	return new XmlMapper(new XmlFactory(StaxUtils.createDefensiveInputFactory()), module);
}
 
Example #9
Source File: Jackson2ObjectMapperBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ObjectMapper create(boolean defaultUseWrapper) {
	JacksonXmlModule module = new JacksonXmlModule();
	module.setDefaultUseWrapper(defaultUseWrapper);
	return new XmlMapper(new XmlFactory(xmlInputFactory()), module);
}
 
Example #10
Source File: BodyTransformer.java    From wiremock-body-transformer with Apache License 2.0 4 votes vote down vote up
private static ObjectMapper initXmlMapper() {
    JacksonXmlModule configuration = new JacksonXmlModule();
    configuration.setXMLTextElementName("value");
    return new XmlMapper(configuration);
}
 
Example #11
Source File: MoreoverResult.java    From streams with Apache License 2.0 4 votes vote down vote up
protected MoreoverResult(String clientId, String xmlString, long start, long end) {
  this.xmlString = xmlString;
  this.clientId = clientId;
  this.start = start;
  this.end = end;
  XmlFactory xmlFactory = new XmlFactory(new InputFactoryImpl(),
      new OutputFactoryImpl());

  JacksonXmlModule module = new JacksonXmlModule();

  module.setDefaultUseWrapper(false);

  xmlMapper = new XmlMapper(xmlFactory, module);

  xmlMapper
      .configure(
          DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
          Boolean.TRUE);
  xmlMapper
      .configure(
          DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
          Boolean.TRUE);
  xmlMapper
      .configure(
          DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY,
          Boolean.TRUE);
  xmlMapper.configure(
      DeserializationFeature.READ_ENUMS_USING_TO_STRING,
      Boolean.TRUE);
  xmlMapper.configure(
      DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
      Boolean.FALSE);

  ObjectMapper mapper = new ObjectMapper();

  mapper
      .configure(
          DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
          Boolean.TRUE);
  mapper.configure(
      DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
      Boolean.TRUE);
  mapper
      .configure(
          DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY,
          Boolean.TRUE);
  mapper.configure(
      DeserializationFeature.READ_ENUMS_USING_TO_STRING,
      Boolean.TRUE);

}
 
Example #12
Source File: XmlBundle.java    From dropwizard-xml with Apache License 2.0 4 votes vote down vote up
public XmlBundle(final JacksonXmlModule jacksonXmlModule) {
    this.xmlMapper = JacksonXML.newXMLMapper( jacksonXmlModule );
}
 
Example #13
Source File: DefaultXmlSerializer.java    From minnal with Apache License 2.0 4 votes vote down vote up
@Override
protected void registerModules(ObjectMapper mapper) {
	JacksonXmlModule module = new JacksonXmlModule();
	module.setDefaultUseWrapper(false);
	mapper.registerModule(module);
}
 
Example #14
Source File: JacksonXML.java    From dropwizard-xml with Apache License 2.0 2 votes vote down vote up
public static XmlMapper newXMLMapper() {

        return newXMLMapper(new JacksonXmlModule());
    }