Skip to content

Commit b38a1a3

Browse files
committed
Add poc for EntityLookupConfiguration replacement.
1 parent 62f96eb commit b38a1a3

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.core;
17+
18+
import java.io.Serializable;
19+
import java.lang.reflect.Member;
20+
import java.util.function.Function;
21+
22+
import org.springframework.util.Assert;
23+
24+
/**
25+
* PoC for REST EntityLookupConfiguration
26+
*
27+
* @author Mark Paluch
28+
*/
29+
public interface MemberReference<T, R> extends Function<T, R>, Serializable {
30+
31+
default Member getMember() {
32+
return resolve(this);
33+
}
34+
35+
public static Member resolve(Object object) {
36+
37+
Assert.notNull(object, "Object must not be null");
38+
Assert.isInstanceOf(Serializable.class, object, "Object must be Serializable");
39+
40+
return new SamParser(MemberReference.class).parse(object.getClass().getClassLoader(), object).getMember();
41+
}
42+
43+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.core;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import java.io.Serializable;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.core.convert.converter.Converter;
25+
26+
/**
27+
* @author Mark Paluch
28+
*/
29+
class MemberReferenceTests {
30+
31+
@Test
32+
void shouldResolveMember() throws NoSuchMethodException {
33+
34+
MemberReference<Person, String> reference = Person::name;
35+
36+
assertThat(reference.getMember()).isEqualTo(Person.class.getMethod("name"));
37+
}
38+
39+
@Test
40+
void retrofitConverter() throws NoSuchMethodException {
41+
42+
Converter<Person, String> reference = convert(Person::name);
43+
44+
assertThat(MemberReference.resolve(reference)).isEqualTo(Person.class.getMethod("name"));
45+
}
46+
47+
static <A, B, T extends Converter<A, B> & Serializable> T convert(T converter) {
48+
return converter;
49+
}
50+
51+
record Person(String name) {
52+
53+
}
54+
}

0 commit comments

Comments
 (0)