Skip to content

Commit 0515b13

Browse files
committed
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.
1 parent 9798411 commit 0515b13

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/main/java/org/springframework/data/repository/query/ReturnedType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -304,7 +304,7 @@ private boolean isDto() {
304304
!isPrimitiveOrWrapper() && //
305305
!Number.class.isAssignableFrom(type) && //
306306
!VOID_TYPES.contains(type) && //
307-
!type.getPackage().getName().startsWith("java.lang");
307+
!type.getPackage().getName().startsWith("java.");
308308
}
309309

310310
private boolean isDomainSubtype() {

src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020

2121
import java.lang.reflect.Method;
2222
import java.math.BigInteger;
23+
import java.time.LocalDateTime;
2324
import java.util.List;
2425

2526
import org.junit.Test;
@@ -154,6 +155,18 @@ public void doesNotConsiderAnEnumProjecting() throws Exception {
154155
assertThat(type.isProjecting(), is(false));
155156
}
156157

158+
/**
159+
* @see DATACMNS-850
160+
*/
161+
@Test
162+
public void considersAllJavaTypesAsNotProjecting() throws Exception {
163+
164+
ReturnedType type = getReturnedType("timeQuery");
165+
166+
assertThat(type.needsCustomConstruction(), is(false));
167+
assertThat(type.isProjecting(), is(false));
168+
}
169+
157170
private static ReturnedType getReturnedType(String methodName, Class<?>... parameters) throws Exception {
158171
return getQueryMethod(methodName, parameters).getResultProcessor().getReturnedType();
159172
}
@@ -191,6 +204,8 @@ interface SampleRepository extends Repository<Sample, Long> {
191204

192205
MyEnum findEnum();
193206

207+
LocalDateTime timeQuery();
208+
194209
static enum MyEnum {
195210
VALUE
196211
}

0 commit comments

Comments
 (0)