Search in sources :

Example 1 with DynamicPropertyFilter

use of org.candlepin.common.jackson.DynamicPropertyFilter in project candlepin by candlepin.

the class JsonProvider method configureHateoasObjectMapper.

private void configureHateoasObjectMapper(ObjectMapper mapper, boolean indentJson) {
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    if (indentJson) {
        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    }
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider = filterProvider.addFilter("ConsumerFilter", new MultiFilter(new HateoasBeanPropertyFilter(), new DynamicPropertyFilter()));
    filterProvider = filterProvider.addFilter("EntitlementFilter", new MultiFilter(new HateoasBeanPropertyFilter(), new DynamicPropertyFilter()));
    filterProvider = filterProvider.addFilter("OwnerFilter", new MultiFilter(new HateoasBeanPropertyFilter(), new DynamicPropertyFilter()));
    filterProvider = filterProvider.addFilter("GuestFilter", new MultiFilter(new HateoasBeanPropertyFilter(), new DynamicPropertyFilter()));
    filterProvider.setDefaultFilter(new DynamicPropertyFilter());
    filterProvider.setFailOnUnknownId(false);
    mapper.setFilterProvider(filterProvider);
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
    AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary);
    mapper.setAnnotationIntrospector(pair);
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospectorPair(com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) HateoasBeanPropertyFilter(org.candlepin.common.jackson.HateoasBeanPropertyFilter) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) DynamicPropertyFilter(org.candlepin.common.jackson.DynamicPropertyFilter) MultiFilter(org.candlepin.common.jackson.MultiFilter) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)

Example 2 with DynamicPropertyFilter

use of org.candlepin.common.jackson.DynamicPropertyFilter in project candlepin by candlepin.

the class ProductDataTest method createObjects.

@Before
public void createObjects() {
    this.mapper = new ObjectMapper();
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.setDefaultFilter(new DynamicPropertyFilter());
    this.mapper.setFilters(filterProvider);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) DynamicPropertyFilter(org.candlepin.common.jackson.DynamicPropertyFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 3 with DynamicPropertyFilter

use of org.candlepin.common.jackson.DynamicPropertyFilter in project candlepin by candlepin.

the class PoolTest method createObjects.

@Before
public void createObjects() {
    this.mapper = new ObjectMapper();
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider = filterProvider.addFilter("PoolFilter", new PoolEventFilter());
    filterProvider = filterProvider.addFilter("OwnerFilter", new HateoasBeanPropertyFilter());
    filterProvider.setDefaultFilter(new DynamicPropertyFilter());
    this.mapper.setFilters(filterProvider);
    beginTransaction();
    try {
        owner = new Owner("testowner");
        ownerCurator.create(owner);
        prod1 = this.createProduct(owner);
        prod2 = this.createProduct(owner);
        Set<Product> providedProducts = new HashSet<>();
        providedProducts.add(prod2);
        pool = TestUtil.createPool(owner, prod1, providedProducts, 1000);
        subscription = TestUtil.createSubscription(owner, prod1);
        subscription.setId(Util.generateDbUUID());
        pool.setSourceSubscription(new SourceSubscription(subscription.getId(), "master"));
        poolCurator.create(pool);
        owner = pool.getOwner();
        consumer = this.createConsumer(owner);
        productCurator.create(prod1);
        poolCurator.create(pool);
        commitTransaction();
    } catch (RuntimeException e) {
        rollbackTransaction();
        throw e;
    }
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) HateoasBeanPropertyFilter(org.candlepin.common.jackson.HateoasBeanPropertyFilter) DynamicPropertyFilter(org.candlepin.common.jackson.DynamicPropertyFilter) PoolEventFilter(org.candlepin.jackson.PoolEventFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)3 DynamicPropertyFilter (org.candlepin.common.jackson.DynamicPropertyFilter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 HateoasBeanPropertyFilter (org.candlepin.common.jackson.HateoasBeanPropertyFilter)2 Before (org.junit.Before)2 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 AnnotationIntrospectorPair (com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair)1 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)1 JaxbAnnotationIntrospector (com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)1 HashSet (java.util.HashSet)1 MultiFilter (org.candlepin.common.jackson.MultiFilter)1 PoolEventFilter (org.candlepin.jackson.PoolEventFilter)1