Skip to content

Commit f864e1d

Browse files
committed
Drop URL support in typed adapter.
1 parent 5c5c345 commit f864e1d

File tree

8 files changed

+10
-24
lines changed

8 files changed

+10
-24
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The HTTP-RPC framework includes the following classes:
5959
* `TemplateEncoder` - class that encodes an object hierarchy using a template document
6060
* `XMLEncoder` - class that encodes an object hierarchy to XML
6161
* `org.httprpc.beans`
62-
* `BeanAdapter` - class that presents the properties of a Java bean object as a map
62+
* `BeanAdapter` - class that presents the properties of a Java bean object as a map and vice versa
6363
* `Ignore` - annotation indicating that a bean property should be ignored
6464
* `Key` - annotation that associates a custom key with a bean property
6565
* `org.httprpc.sql`
@@ -786,7 +786,6 @@ If the value is already an instance of the requested type, it is returned as is.
786786
* If the target type is a `String`, the value is adapted via its `toString()` method.
787787
* If the target type is `java.util.Date`, the value is parsed or coerced to a long value representing epoch time in milliseconds and then converted to a `Date`.
788788
* If the target type is `java.util.time.LocalDate`, `java.util.time.LocalTime`, or `java.util.time.LocalDateTime`, the value is converted to a string and parsed using the appropriate `parse()` method.
789-
* If the target type is `java.net.URL`, the value is first converted to a string and then to a URL.
790789
* If the target type is `java.util.List` or `java.util.Map`, the value is wrapped in an adapter of the same type that automatically adapts its sub-elements.
791790

792791
Otherwise, the target is assumed to be a bean interface, and the value is assumed to be a map. The return value is an implementation of the given interface that maps accessor methods to entries in the map. Property values are adapted as described above.

httprpc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repositories {
2525
dependencies {
2626
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
2727

28-
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.2")
28+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.2")
2929
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
3030
}
3131

httprpc/src/main/java/org/httprpc/beans/BeanAdapter.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,6 @@ private static Object adapt(Object value, HashMap<Class<?>, HashMap<String, Meth
376376
* representation is parsed using {@link LocalTime#parse(CharSequence)}.</li>
377377
* <li>If the target type is {@link LocalDateTime}, the value's string
378378
* representation is parsed using {@link LocalDateTime#parse(CharSequence)}.</li>
379-
* <li>If the target type is {@link URL}, the value's string representation
380-
* is adapted via {@link URL#URL(String)}.
381379
* </ul>
382380
*
383381
* If the target type is a {@link List}, the value is wrapped in an adapter
@@ -505,12 +503,6 @@ private static Object adapt(Object value, Class<?> type) {
505503
return LocalTime.parse(value.toString());
506504
} else if (type == LocalDateTime.class) {
507505
return LocalDateTime.parse(value.toString());
508-
} else if (type == URL.class) {
509-
try {
510-
return new URL(value.toString());
511-
} catch (MalformedURLException exception) {
512-
throw new IllegalArgumentException(exception);
513-
}
514506
} else if (value instanceof Map<?, ?>) {
515507
return adaptBean((Map<?, ?>)value, type);
516508
} else {
@@ -526,16 +518,15 @@ private static Object adaptBean(Map<?, ?> map, Class<?> type) {
526518
throw new IllegalArgumentException("Type is not an interface.");
527519
}
528520

529-
return type.cast(Proxy.newProxyInstance(type.getClassLoader(),
530-
new Class[] {type}, (proxy, method, arguments) -> {
531-
String key = getKey(method);
521+
return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[] {type}, (proxy, method, arguments) -> {
522+
String key = getKey(method);
532523

533-
if (key == null) {
534-
throw new UnsupportedOperationException();
535-
}
524+
if (key == null) {
525+
throw new UnsupportedOperationException();
526+
}
536527

537-
return adapt(map.get(key), method.getGenericReturnType());
538-
}));
528+
return adapt(map.get(key), method.getGenericReturnType());
529+
}));
539530
}
540531

541532
/**

httprpc/src/test/java/org/httprpc/beans/BeanAdapterTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ public void testBeanAdapter2() throws IOException {
124124
Assertions.assertEquals(LocalTime.parse("10:45"), result.getLocalTime());
125125
Assertions.assertEquals(LocalDateTime.parse("2018-06-28T10:45"), result.getLocalDateTime());
126126

127-
Assertions.assertEquals(new URL("http://localhost:8080"), result.getURL());
128-
129127
Assertions.assertTrue(result.getNestedBean().getFlag());
130128

131129
Assertions.assertEquals(2L, ((Number)result.getList().get(0)).longValue());

httprpc/src/test/java/org/httprpc/beans/TestBean.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public LocalDateTime getLocalDateTime() {
9898
return LocalDateTime.parse("2018-06-28T10:45");
9999
}
100100

101-
@Override
102101
public URL getURL() {
103102
try {
104103
return new URL("http://localhost:8080");

httprpc/src/test/java/org/httprpc/beans/TestInterface.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public interface NestedInterface {
3636
public LocalDate getLocalDate();
3737
public LocalTime getLocalTime();
3838
public LocalDateTime getLocalDateTime();
39-
public URL getURL();
4039
public NestedInterface getNestedBean();
4140
public List<?> getList();
4241
public List<? extends NestedInterface> getNestedBeanList();

httprpc/src/test/resources/org/httprpc/beans/test.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"localDate": "2018-06-28",
99
"localTime": "10:45",
1010
"localDateTime": "2018-06-28T10:45",
11-
"URL": "http://localhost:8080",
1211
"nestedBean": {
1312
"flag": true
1413
},

0 commit comments

Comments
 (0)