use of io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider in project crnk-framework by crnk-project.
the class AbstractQuerySpecTest method setup.
@Before
public void setup() {
ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(new NullPropertiesProvider(), ImmutableList.of(new OffsetLimitPagingBehavior(), new CustomOffsetLimitPagingBehavior()), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider()) {
@Override
protected List<ResourceField> getResourceFields(Class<?> resourceClass) {
List<ResourceField> fields = super.getResourceFields(resourceClass);
if (resourceClass == Task.class) {
// add additional field that is not defined on the class
String name = "computedAttribute";
ResourceFieldAccess access = new ResourceFieldAccess(true, true, true, true, true);
InformationBuilder informationBuilder = new DefaultInformationBuilder(new TypeParser());
InformationBuilder.Field fieldBuilder = informationBuilder.createResourceField();
fieldBuilder.type(Integer.class);
fieldBuilder.jsonName(name);
fieldBuilder.underlyingName(name);
fieldBuilder.access(access);
fieldBuilder.accessor(new ResourceFieldAccessor() {
public Object getValue(Object resource) {
return 13;
}
public void setValue(Object resource, Object fieldValue) {
}
});
fields.add(fieldBuilder.build());
}
return fields;
}
};
SimpleModule testModule = new SimpleModule("test");
testModule.addResourceInformationProvider(resourceInformationProvider);
CrnkBoot boot = new CrnkBoot();
boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://127.0.0.1"));
boot.addModule(testModule);
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(getResourceSearchPackage()));
boot.boot();
moduleRegistry = boot.getModuleRegistry();
querySpecConverter = new DefaultQuerySpecConverter(moduleRegistry);
resourceRegistry = boot.getResourceRegistry();
}
Aggregations