Java Code Examples for com.fasterxml.jackson.dataformat.xml.JacksonXmlModule#setDefaultUseWrapper()

The following examples show how to use com.fasterxml.jackson.dataformat.xml.JacksonXmlModule#setDefaultUseWrapper() . 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: 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 4
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 5
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 6
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 7
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 8
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 9
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);
}