com.vaadin.fusion.endpointransfermapper.
Class EndpointTransferMapper
- java.lang.Object
-
- com.vaadin.fusion.endpointransfermapper.EndpointTransferMapper
-
public class EndpointTransferMapper extends Object
Defines mappings for certain endpoint types to corresponding transfer types. This allows using beans / classes in endpoints which cannot be serialized by the standard bean serialization.
Each endpoint parameter value coming from the client is passed through a registered mapper for that endpoint type before the values are passed to the endpoint methods.
Each endpoint return value is passed through a registered mapper before the value is serialized by the normal serialization mechanism and then sent to the client.
The endpoint TypeScript is generated based on the mapped types.
For example, a method like
public Page<Person> list(Pageable pageable) { }
generates a TypeScript and converts data as if the method was defined as
public List<Person> list(com.vaadin.fusion.mappedtypes.Pageable pageable) { }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static interface
EndpointTransferMapper.Mapper<ENDPOINTTYPE,TRANSFERTYPE>
A mapper for endpoint values that is capable of converting between the given endpoint and transfer type.
-
Constructor Summary
Constructors Constructor and Description EndpointTransferMapper()
Creates a new instance.
-
Method Summary
All Methods Modifier and Type Method and Description <T> EndpointTransferMapper.Mapper
getMapper(Class<T> endpointType)
Gets the mapper for the given endpoint type.
Class<?>
getTransferType(Class<?> endpointType)
Gets the transfer type for the given endpoint type.
String
getTransferType(String endpointType)
Gets the transfer type for the given endpoint type.
<T> T
toEndpointType(Object transferValue, Class<T> endpointType)
Converts the given object from its transfer type to the given endpoint type.
Object
toTransferType(Object endpointValue)
Converts the given object from its endpoint type to its transfer type.
-
-
-
Method Detail
-
getTransferType
public Class<?> getTransferType(Class<?> endpointType)
Gets the transfer type for the given endpoint type.
NOTE that this is intended for checking the type of a value being sent at runtime and thus checks also the super types / interfaces of the given type.
The returned transfer type is the same as the endpoint type if no conversion is needed.
Parameters:
endpointType
- the endpoint typeReturns:
the transfer type or null if no mapping exists
-
getTransferType
public String getTransferType(String endpointType)
Gets the transfer type for the given endpoint type.
NOTE that this is intended to be used when generating TypeScript and it DOES NOT check super types / interfaces of the given type.
The returned transfer type is the same as the endpoint type if no conversion is needed.
Parameters:
endpointType
- the endpoint typeReturns:
the transfer type or null if no mapping exists
-
getMapper
public <T> EndpointTransferMapper.Mapper getMapper(Class<T> endpointType)
Gets the mapper for the given endpoint type.
NOTE that this is intended for runtime and thus checks also the super types / interfaces of the given type.
Type Parameters:
T
- the endpoint typeParameters:
endpointType
- the endpoint typeReturns:
the transfer type or null if no mapper exists
-
toTransferType
public Object toTransferType(Object endpointValue)
Converts the given object from its endpoint type to its transfer type.
Parameters:
endpointValue
- the value returned from the endpointReturns:
the value converted to its transfer type
-
toEndpointType
public <T> T toEndpointType(Object transferValue, Class<T> endpointType)
Converts the given object from its transfer type to the given endpoint type.
Type Parameters:
T
- the endpoint typeParameters:
transferValue
- the value transferred over the networkendpointType
- the value type declared in the endpoint, as parameter or return typeReturns:
the value converted to its endpoint type
-
-