Skip to content

Commit 3f256aa

Browse files
committed
Update README.md.
1 parent 57e3afb commit 3f256aa

3 files changed

Lines changed: 11 additions & 155 deletions

File tree

README.md

Lines changed: 7 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ var sum2 = mathServiceProxy.getSum(listOf(1.0, 2.0, 3.0)); // 6.0
451451
var average = mathServiceProxy.getAverage(listOf(1.0, 2.0, 3.0, 4.0, 5.0)); // 3.0
452452
```
453453

454-
The [`Name`](#custom-parameter-names) and [`Required`](#required-parameters) annotations may also be applied to proxy method parameters. The `WebServiceProxy.Configuration` annotation can be used to further customize request processing.
454+
The [`Required`](#required-parameters) and [`Name`](#custom-parameter-names) annotations may also be applied to proxy method parameters. The `WebServiceProxy.Configuration` annotation can be used to further customize request processing.
455455

456456
Path variables and body content are handled as described for [`WebService`](#webservice). Body parameters are required for `POST` and `PUT` methods. A body parameter of type `Void` may be used to indicate that a method does not accept a body.
457457

@@ -577,14 +577,14 @@ course.setName("CS 101");
577577
course.setBuilding("Technology Lab");
578578
course.setRoomNumber(210);
579579

580-
var courseAdapter = new BeanAdapter(course);
580+
var map = new BeanAdapter(course);
581581

582-
System.out.println(courseAdapter.get("name")); // CS 101
583-
System.out.println(courseAdapter.get("building")); // Technology Lab
584-
System.out.println(courseAdapter.get("roomNumber")); // 210
582+
System.out.println(map.get("name")); // CS 101
583+
System.out.println(map.get("building")); // Technology Lab
584+
System.out.println(map.get("roomNumber")); // 210
585585
```
586586

587-
`BeanAdapter` can also be used to facilitate type-safe access to loosely typed data structures:
587+
It can also be used to facilitate type-safe access to loosely typed data structures:
588588

589589
```java
590590
var map = mapOf(
@@ -629,83 +629,7 @@ System.out.println(weather.getLow()); // 43.5
629629

630630
Note that concrete types are coerced "eagerly" (before the `coerce()` method returns), while interfaces are coerced "lazily" (when a property is accessed).
631631

632-
### Required Properties
633-
The `Required` annotation introduced [previously](#required-parameters) can also be used to indicate that a property must contain a value. For example:
634-
635-
```java
636-
public class Vehicle {
637-
private String manufacturer;
638-
private Integer year;
639-
640-
@Required
641-
public String getManufacturer() {
642-
return manufacturer;
643-
}
644-
645-
public void setManufacturer(String manufacturer) {
646-
this.manufacturer = manufacturer;
647-
}
648-
649-
@Required
650-
public Integer getYear() {
651-
return year;
652-
}
653-
654-
public void setYear(Integer year) {
655-
this.year = year;
656-
}
657-
}
658-
```
659-
660-
Because both "manufacturer" and "year" are required, an attempt to coerce an empty map to a `Vehicle` instance would produce an `IllegalArgumentException`:
661-
662-
```java
663-
var vehicle = BeanAdapter.coerce(mapOf(), Vehicle.class); // throws
664-
```
665-
666-
Additionally, although the annotation will not prevent a caller from programmatically assigning a `null` value to either property, attempting to dynamically set an invalid value will generate an `IllegalArgumentException`:
667-
668-
```java
669-
var vehicle = new Vehicle();
670-
671-
var vehicleAdapter = new BeanAdapter(vehicle);
672-
673-
vehicleAdapter.put("manufacturer", null); // throws
674-
```
675-
676-
Similarly, attempting to dynamically access an invalid value will result in an `UnsupportedOperationException`:
677-
678-
```java
679-
vehicleAdapter.get("manufacturer"); // throws
680-
```
681-
682-
### Custom Property Names
683-
The `Name` annotation introduced [previously](#custom-parameter-names) can also be used with bean properties. For example:
684-
685-
```java
686-
public class Person {
687-
private String firstName = null;
688-
private String lastName = null;
689-
690-
@Name("first_name")
691-
public String getFirstName() {
692-
return firstName;
693-
}
694-
695-
public void setFirstName(String firstName) {
696-
this.firstName = firstName;
697-
}
698-
699-
@Name("last_name")
700-
public String getLastName() {
701-
return lastName;
702-
}
703-
704-
public void setLastName(String lastName) {
705-
this.lastName = lastName;
706-
}
707-
}
708-
```
632+
The `Required` and `Name` annotations introduced previously can also be used with bean properties.
709633

710634
## QueryBuilder and ResultSetAdapter
711635
The `QueryBuilder` class provides support for programmatically constructing and executing SQL queries. For example, given the following tables (adapted from the MySQL tutorial):

kilo-test/src/test/java/org/httprpc/kilo/examples/Examples.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public static void main(String[] args) {
6262
execute("Adapt Bean", Examples::adaptBean);
6363
execute("Coerce Bean", Examples::coerceBean);
6464
execute("Interface Proxy", Examples::interfaceProxy);
65-
execute("Required Property 1", Examples::requiredProperty1);
66-
execute("Required Property 2", Examples::requiredProperty2);
6765

6866
execute("Element Adapter", Examples::elementAdapter);
6967

@@ -215,11 +213,11 @@ public static void adaptBean() {
215213
course.setBuilding("Technology Lab");
216214
course.setRoomNumber(210);
217215

218-
var courseAdapter = new BeanAdapter(course);
216+
var map = new BeanAdapter(course);
219217

220-
System.out.println(courseAdapter.get("name")); // CS 101
221-
System.out.println(courseAdapter.get("building")); // Technology Lab
222-
System.out.println(courseAdapter.get("roomNumber")); // 210
218+
System.out.println(map.get("name")); // CS 101
219+
System.out.println(map.get("building")); // Technology Lab
220+
System.out.println(map.get("roomNumber")); // 210
223221
}
224222

225223
public static void coerceBean() {
@@ -252,32 +250,6 @@ public static void interfaceProxy() {
252250
System.out.println(weather.getLow()); // 43.5
253251
}
254252

255-
public static void requiredProperty1() {
256-
try {
257-
BeanAdapter.coerce(mapOf(), Vehicle.class);
258-
} catch (IllegalArgumentException exception) {
259-
System.out.println(exception.getMessage());
260-
}
261-
}
262-
263-
public static void requiredProperty2() {
264-
var vehicle = new Vehicle();
265-
266-
var vehicleAdapter = new BeanAdapter(vehicle);
267-
268-
try {
269-
vehicleAdapter.put("manufacturer", null);
270-
} catch (IllegalArgumentException exception) {
271-
System.out.println(exception.getMessage());
272-
}
273-
274-
try {
275-
vehicleAdapter.get("manufacturer");
276-
} catch (UnsupportedOperationException exception) {
277-
System.out.println(exception.getMessage());
278-
}
279-
}
280-
281253
@SuppressWarnings("unchecked")
282254
public static void elementAdapter() throws SAXException, IOException {
283255
var documentBuilder = ElementAdapter.newDocumentBuilder();

kilo-test/src/test/java/org/httprpc/kilo/examples/Vehicle.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)