Fix serialization issues

This commit is contained in:
Timo Westkämper 2015-05-20 20:58:28 +03:00 committed by Ruben Dijkstra
parent 60c46b1d71
commit 25d47c12b4
5 changed files with 86 additions and 9 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
@ -72,7 +72,7 @@
<artifactId>jdepend</artifactId>
<version>2.9.1</version>
<scope>test</scope>
</dependency>
</dependency>
</dependencies>
<build>
@ -141,4 +141,4 @@
<properties>
<bridge-method.version>1.13</bridge-method.version>
</properties>
</project>
</project>

View File

@ -82,4 +82,16 @@ public abstract class FactoryExpressionBase<T> extends ExpressionBase<T> impleme
return new FactoryExpressionWrapper<T>(this);
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof FactoryExpression) {
return getClass().equals(o.getClass())
&& getArgs().equals(((FactoryExpression) o).getArgs());
} else {
return false;
}
}
}

View File

@ -13,6 +13,7 @@
*/
package com.querydsl.core.types.dsl;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
@ -25,7 +26,7 @@ import com.querydsl.core.util.ReflectionUtils;
/**
* {@code PathBuilderValidator} validates {@link PathBuilder} properties at creation time
*/
public interface PathBuilderValidator {
public interface PathBuilderValidator extends Serializable {
/**
* Validates the given property of given class

View File

@ -20,7 +20,7 @@ import java.util.List;
* @author tiwe
*
*/
public class Concatenation extends ExpressionBase<String> implements FactoryExpression<String> {
public class Concatenation extends FactoryExpressionBase<String> {
private static final long serialVersionUID = -355693583588722395L;

View File

@ -3,15 +3,79 @@ package com.querydsl.core.types;
import static com.querydsl.core.testutil.Serialization.serialize;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.SimplePath;
import org.junit.Test;
import org.reflections.Reflections;
import com.google.common.collect.Maps;
import com.querydsl.core.DefaultQueryMetadata;
import com.querydsl.core.QueryMetadata;
import com.querydsl.core.group.GroupBy;
import com.querydsl.core.group.GroupExpression;
import com.querydsl.core.testutil.Serialization;
import com.querydsl.core.types.dsl.*;
public class SerializationTest {
public enum Gender { MALE, FEMALE }
@Test
public void roundtrip() throws Exception {
public void Expressions() throws Exception {
Map<Class<?>, Object> args = Maps.newHashMap();
args.put(Object.class, "obj");
args.put(BeanPath.class, new EntityPathBase<Object>(Object.class, "obj"));
args.put(Class.class, Integer.class);
args.put(Class[].class, new Class[]{Object.class, Object.class});
args.put(java.util.Date.class, new java.util.Date(0));
args.put(java.sql.Date.class, new java.sql.Date(0));
args.put(java.sql.Time.class, new java.sql.Time(0));
args.put(java.sql.Timestamp.class, new java.sql.Timestamp(0));
args.put(Expression.class, Expressions.enumPath(Gender.class, "e"));
args.put(Expression[].class, new Expression<?>[]{
Expressions.enumPath(Gender.class, "e"), Expressions.stringPath("s")});
args.put(FactoryExpression.class, Projections.tuple(Expressions.stringPath("str")));
args.put(GroupExpression.class, GroupBy.avg(Expressions.numberPath(Integer.class, "num")));
args.put(Number.class, 1);
args.put(Operator.class, Ops.AND);
args.put(Path.class, Expressions.stringPath("str"));
args.put(PathBuilderValidator.class, PathBuilderValidator.DEFAULT);
args.put(PathMetadata.class, PathMetadataFactory.forVariable("obj"));
args.put(PathInits.class, PathInits.DEFAULT);
args.put(Predicate.class, Expressions.path(Object.class, "obj").isNull());
args.put(QueryMetadata.class, new DefaultQueryMetadata());
args.put(String.class, "obj");
Reflections reflections = new Reflections();
Set<Class<? extends Expression>> types = reflections.getSubTypesOf(Expression.class);
for (Class<?> type : types) {
if (!type.isInterface() && !type.isMemberClass() && !Modifier.isAbstract(type.getModifiers())) {
for (Constructor<?> c : type.getConstructors()) {
Object[] parameters = new Object[c.getParameterTypes().length];
for (int i = 0; i < c.getParameterTypes().length; i++) {
parameters[i] = Objects.requireNonNull(args.get(c.getParameterTypes()[i]),
c.getParameterTypes()[i].getName());
}
c.setAccessible(true);
Object o = c.newInstance(parameters);
assertEquals(o, Serialization.serialize(o));
}
}
}
}
@Test
public void Order() {
OrderSpecifier<?> order = new OrderSpecifier<String>(Order.ASC, Expressions.stringPath("str"));
assertEquals(order, Serialization.serialize(order));
}
@Test
public void Roundtrip() throws Exception {
Path<?> path = ExpressionUtils.path(Object.class, "entity");
SimplePath<?> path2 = Expressions.path(Object.class, "entity");
assertEquals(path, serialize(path));