use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project oap by oaplatform.
the class Binder method initialize.
private static ObjectMapper initialize(ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion, boolean skipInputNulls) {
if (mapper instanceof XmlMapper) {
((XmlMapper) mapper).setDefaultUseWrapper(false);
((XmlMapper) mapper).configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
}
AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
mapper.getDeserializationConfig().with(introspector);
mapper.getSerializationConfig().with(introspector);
mapper.registerModule(new AfterburnerModule());
mapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(true));
mapper.registerModule(new JodaModule());
mapper.registerModule(new ExtModule());
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS);
mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
// todo remove after kernel cleanup
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
if (skipInputNulls)
mapper.setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SKIP));
if (!nonNullInclusion)
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
modules.forEach(mapper::registerModule);
if (defaultTyping)
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
return mapper;
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project tutorials by eugenp.
the class SimpleBeanForCapitalizedFields method whenJavaSerializedToXmlFile_thenCorrect.
@Test
public void whenJavaSerializedToXmlFile_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.writeValue(new File("target/simple_bean.xml"), new SimpleBean());
File file = new File("target/simple_bean.xml");
assertNotNull(file);
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project tutorials by eugenp.
the class SimpleBeanForCapitalizedFields method whenJavaGotFromXmlStrWithCapitalElem_thenCorrect.
@Test
public void whenJavaGotFromXmlStrWithCapitalElem_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
SimpleBeanForCapitalizedFields value = xmlMapper.readValue("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>", SimpleBeanForCapitalizedFields.class);
assertTrue(value.getX() == 1 && value.getY() == 2);
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project tutorials by eugenp.
the class SimpleBeanForCapitalizedFields method whenJavaGotFromXmlStr_thenCorrect.
@Test
public void whenJavaGotFromXmlStr_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
SimpleBean value = xmlMapper.readValue("<SimpleBean><x>1</x><y>2</y></SimpleBean>", SimpleBean.class);
assertTrue(value.getX() == 1 && value.getY() == 2);
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project alluxio by Alluxio.
the class TestCase method run.
/**
* Runs the test case.
*/
public void run() throws Exception {
String expected = "";
if (mExpectedResult != null) {
switch(mOptions.getContentType()) {
case TestCaseOptions.JSON_CONTENT_TYPE:
{
ObjectMapper mapper = new ObjectMapper();
if (mOptions.isPrettyPrint()) {
expected = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mExpectedResult);
} else {
expected = mapper.writeValueAsString(mExpectedResult);
}
break;
}
case TestCaseOptions.XML_CONTENT_TYPE:
{
XmlMapper mapper = new XmlMapper();
if (mOptions.isPrettyPrint()) {
expected = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mExpectedResult);
} else {
expected = mapper.writeValueAsString(mExpectedResult);
}
break;
}
default:
throw new InvalidArgumentException("Invalid content type in TestCaseOptions!");
}
}
String result = call();
Assert.assertEquals(mEndpoint, expected, result);
}
Aggregations