|
|
## [Home](https://git.opendfki.de/delight/delight/wikis/Home) | [Documentation](https://git.opendfki.de/delight/delight/wikis/Documentation) | [People / Contact](https://git.opendfki.de/delight/delight/wikis/people)
|
|
|
---
|
|
|
### Using Third Party Types in your API
|
|
|
|
|
|
Sometimes it is dicouraged to have any XML-RPC or Delight reference in an interface class. In order to still use this interface
|
|
|
with Delight a ```javaParameterConverterRegistry``` has been introduced. See also [Using third party types in your API](ExampleUsingThirdPartyTypes).
|
|
|
|
|
|
```java
|
|
|
*** SOMETIMES DISCOURAGED ***
|
|
|
@ConverterMappings(
|
|
|
@Mapping(type=URL.class,converter=URLConverter.class)
|
|
|
)
|
|
|
public interface Api
|
|
|
{
|
|
|
URL getHomepageLocation();
|
|
|
void addSite( URL url );
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Alternative with **ParameterConverterRegistry:**
|
|
|
|
|
|
```java
|
|
|
public interface Api
|
|
|
{
|
|
|
URL getHomepageLocation();
|
|
|
void addSite( URL url );
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Now, without having to annotate the interface invoking the methods looks like this:
|
|
|
```java
|
|
|
ParameterConverterRegistry.setParameterConverterForClass( URL.class, URLConverter.class );
|
|
|
Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port );
|
|
|
|
|
|
URL homepageUrl = remote_api.getHomepageLocation();
|
|
|
InputStream is = homepageUrl.openStream();
|
|
|
...
|
|
|
|
|
|
remote_api.addSite( new URL( "http://middle.of.nowhere" ) );
|
|
|
|
|
|
...
|
|
|
```
|
|
|
|
|
|
**NOTE:** Client **AND** Server have to register the converter prior to a remote call.
|
|
|
|
|
|
|
|
|
|
|
|
Examples in source code: [here](https://git.opendfki.de/delight/delight/tree/master/example-delight-webapp) |
|
|
\ No newline at end of file |