use of com.fasterxml.jackson.module.afterburner.AfterburnerModule 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.module.afterburner.AfterburnerModule in project core-ng-project by neowu.
the class JSONMapper method createObjectMapper.
private static ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new AfterburnerModule());
mapper.setDateFormat(new StdDateFormat());
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true);
mapper.setAnnotationIntrospector(new JSONAnnotationIntrospector());
return mapper;
}
use of com.fasterxml.jackson.module.afterburner.AfterburnerModule in project jackson-module-afterburner by FasterXML.
the class VLTBet method testIssue.
public void testIssue() throws Exception {
// create this ridiculously complicated object
ItemData data = new ItemData();
data.denomination = 100;
Item item = new Item();
item.data = data;
item.productId = 123;
List<Item> itemList = new ArrayList<Item>();
itemList.add(item);
PlaceOrderRequest order = new PlaceOrderRequest();
order.orderId = 68723496;
order.userId = "123489043";
order.amount = 250;
order.status = "placed";
order.items = itemList;
final Date now = new Date(999999L);
order.createdAt = now;
order.updatedAt = now;
ObjectMapper vanillaMapper = new ObjectMapper();
ObjectMapper abMapper = new ObjectMapper();
abMapper.registerModule(new AfterburnerModule());
// First: ensure that serialization produces identical output
String origJson = vanillaMapper.writerWithDefaultPrettyPrinter().writeValueAsString(order);
String abJson = abMapper.writerWithDefaultPrettyPrinter().writeValueAsString(order);
assertEquals(origJson, abJson);
// Then read the string and turn it back into an object
// this will cause an exception unless the AfterburnerModule is commented out
order = abMapper.readValue(abJson, PlaceOrderRequest.class);
assertNotNull(order);
assertEquals(250, order.amount);
}
use of com.fasterxml.jackson.module.afterburner.AfterburnerModule in project jackson-module-afterburner by FasterXML.
the class TestDeserializePerf method main.
public static void main(String[] args) throws Exception {
// JsonFactory f = new org.codehaus.jackson.smile.SmileFactory();
JsonFactory f = new JsonFactory();
ObjectMapper mapperSlow = new ObjectMapper(f);
ObjectMapper mapperFast = new ObjectMapper(f);
// !!! TEST -- to get profile info, comment out:
// mapperSlow.registerModule(new AfterburnerModule());
mapperFast.registerModule(new AfterburnerModule());
new TestDeserializePerf().testWith(mapperSlow, mapperFast);
}
use of com.fasterxml.jackson.module.afterburner.AfterburnerModule in project ninja by ninjaframework.
the class XmlMapperProvider method get.
@Override
public XmlMapper get() {
JacksonXmlModule module = new JacksonXmlModule();
// Check out: https://github.com/FasterXML/jackson-dataformat-xml
// setDefaultUseWrapper produces more similar output to
// the Json output. You can change that with annotations in your
// models.
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);
xmlMapper.registerModule(new AfterburnerModule());
return xmlMapper;
}
Aggregations