Skip to content

Instantly share code, notes, and snippets.

View marcus-nl's full-sized avatar

Marcus marcus-nl

  • XLRIT
  • The Netherlands
View GitHub Profile
@marcus-nl
marcus-nl / ResourcePatternResolverTest.java
Last active August 29, 2015 14:04
Use Spring ResourcePatternResolver to find subclasses
@Inject
private ResourceLoader resourceLoader;
@Test
public void processClasses() throws IOException, ClassNotFoundException {
TypeFilter typeFilter = new AssignableTypeFilter(MyClass.class);
ResourcePatternResolver resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourceLoader);
String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
@marcus-nl
marcus-nl / ExplicitPropertiesFilter.java
Last active August 29, 2015 14:05
Jackson: Explicit Properties
public class ExplicitPropertiesFilter extends SimpleBeanPropertyFilter {
@Override
protected boolean include(BeanPropertyWriter writer) {
JsonProperty anno = writer.getAnnotation(JsonProperty.class);
return anno != null;
}
@Override
protected boolean include(PropertyWriter writer) {
@marcus-nl
marcus-nl / DynamicVisitor.java
Created August 15, 2014 15:32
Dynamic Visitor Pattern
public abstract class DynamicVisitor {
private final Class<? extends DynamicVisitor> thisClass;
private final MethodMap methods;
protected DynamicVisitor() {
this.thisClass = getClass();
this.methods = new MethodMap();
for (Method m : thisClass.getMethods()) {
if ("visit".equals(m.getName())) {
@marcus-nl
marcus-nl / JacksonConfig.java
Created August 16, 2014 10:08
Jackson: register subtypes using Reflections
private void registerSubtypes(ObjectMapper objectMapper, Class<?> base) {
Reflections reflections = new Reflections(base.getPackage().getName());
Class<?>[] subTypes = reflections.getSubTypesOf(base).toArray(new Class<?>[0]);
objectMapper.registerSubtypes(subTypes);
}
@marcus-nl
marcus-nl / EmberSchemaGeneratorExample.java
Created September 13, 2014 11:29
EmberSchema to JSON
EmberSchema schema = ...;
JsonGenerator jgen = objectMapper.getFactory()
.createGenerator(System.out)
.useDefaultPrettyPrinter();
jgen.writeObject(schema);
jgen.close();
@marcus-nl
marcus-nl / fiddle.response.json
Last active August 29, 2015 14:23
JSFiddle test data (Bootgrid)
{
"current": 1,
"rowCount": 50,
"rows": [
{
"id": 1122,
"sender": "eric@facebook.com",
"received": "2015-06-21T18:41:56"
},
{
@marcus-nl
marcus-nl / fiddle.response.json
Created June 26, 2015 13:04
JSFiddle test data (DataTables)
{
"current": 1,
"rowCount": 50,
"data": [
{
"id": 1122,
"sender": "eric@facebook.com",
"received": "2015-06-21T18:41:56"
},
{
@marcus-nl
marcus-nl / fiddle.response.json
Last active August 29, 2015 14:23
JSON current
{
"data":[
[
"1",
"iPad2 (8GB)",
"322"
],
[
"2",
"iPad2 (16GB)",
public class HibernateSchemaManagementTool implements SchemaManagementTool, ServiceRegistryAwareService {
private ServiceRegistry serviceRegistry;
@Override
public SchemaCreator getSchemaCreator(Map options) {
// TODO use AvailableSettings.SCHEMA_CREATE_FILTER
return new SchemaCreatorImpl( getSchemaFilter( options, "hibernate.schema.create.filter" ) );
}
@Override
@marcus-nl
marcus-nl / 1. ExampleProcessEnginePlugin.java
Last active July 29, 2019 07:48
Camunda custom form handling example
class ExampleProcessEnginePlugin extends AbstractProcessEnginePlugin {
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
super.preInit(processEngineConfiguration);
ExampleFormEngine formEngine = new ExampleFormEngine();
processEngineConfiguration.setCustomFormEngines(singletonList(formEngine));
processEngineConfiguration.setCustomPreBPMNParseListeners(singletonList(new ExampleParseListener(formEngine)));
}
}