Commit c72e9c4d authored by Matija Obreza's avatar Matija Obreza

BasicModelFilter#toString() as JSON

parent 855d7fc0
......@@ -17,18 +17,28 @@ package org.genesys.blocks.model.filters;
import java.util.Set;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.BasicModel;
import org.genesys.blocks.model.QBasicModel;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
/**
* {@link BasicModel} match by sample filters.
*/
public abstract class BasicModelFilter {
private static final ObjectMapper jsonizer = new ObjectMapper();
static {
// Any objectMapper configuration goes here
jsonizer.setSerializationInclusion(Include.NON_DEFAULT);
}
/** The id. */
public Set<Long> id;
......@@ -38,7 +48,7 @@ public abstract class BasicModelFilter {
* @return the predicate
*/
public abstract Predicate buildQuery();
/**
* Builds the query.
*
......@@ -50,4 +60,37 @@ public abstract class BasicModelFilter {
builder.and(basicModel.id.in(id));
}
}
// @Override
// public int hashCode() {
// String str = toString();
//
// final int prime = 31;
// int result = 1;
// result = prime * result + ((str == null) ? 0 : str.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// BasicModelFilter other = (BasicModelFilter) obj;
// if (!this.toString().equals(other.toString()))
// return false;
// return true;
// }
@Override
public String toString() {
try {
return jsonizer.writeValueAsString(this);
} catch (JsonProcessingException e) {
throw new RuntimeException("Could not serialize to JSON: " + e.getMessage(), e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment