From 0515b1308c2aa4d7c5b78e6ab15a2357ecbc6bb3 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 28 Apr 2016 16:43:06 +0200 Subject: [PATCH] DATACMNS-850 - ReturnedClass now does not consider core Java types DTOs. We now completely ignore all core Java types (i.e. types with a package name starting with "java.") from being DTOs. This allows query methods to project on date time types, too. --- .../data/repository/query/ReturnedType.java | 4 ++-- .../repository/query/ReturnedTypeUnitTests.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/query/ReturnedType.java b/src/main/java/org/springframework/data/repository/query/ReturnedType.java index 73123c8ef..afc615ef3 100644 --- a/src/main/java/org/springframework/data/repository/query/ReturnedType.java +++ b/src/main/java/org/springframework/data/repository/query/ReturnedType.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -304,7 +304,7 @@ public abstract class ReturnedType { !isPrimitiveOrWrapper() && // !Number.class.isAssignableFrom(type) && // !VOID_TYPES.contains(type) && // - !type.getPackage().getName().startsWith("java.lang"); + !type.getPackage().getName().startsWith("java."); } private boolean isDomainSubtype() { diff --git a/src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java b/src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java index 02468b7cd..ab3eeab55 100644 --- a/src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java +++ b/src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import static org.junit.Assert.*; import java.lang.reflect.Method; import java.math.BigInteger; +import java.time.LocalDateTime; import java.util.List; import org.junit.Test; @@ -154,6 +155,18 @@ public class ReturnedTypeUnitTests { assertThat(type.isProjecting(), is(false)); } + /** + * @see DATACMNS-850 + */ + @Test + public void considersAllJavaTypesAsNotProjecting() throws Exception { + + ReturnedType type = getReturnedType("timeQuery"); + + assertThat(type.needsCustomConstruction(), is(false)); + assertThat(type.isProjecting(), is(false)); + } + private static ReturnedType getReturnedType(String methodName, Class... parameters) throws Exception { return getQueryMethod(methodName, parameters).getResultProcessor().getReturnedType(); } @@ -191,6 +204,8 @@ public class ReturnedTypeUnitTests { MyEnum findEnum(); + LocalDateTime timeQuery(); + static enum MyEnum { VALUE }