Interface CommonMappingInterface<S>
- Type Parameters:
S- the entity type returned by the service implementation
- All Known Implementing Classes:
HardwareIdMapper, MsftDnsClientServerAddressMapper, MsftNetAdapterMapper, MsftNetAdapterToIpAndDnsAndProfileMapper, MsftNetConnectionProfileMapper, MsftNetIpAddressMapper, Win32AssociatedProcessorMemoryMapper, Win32BaseboardMapper, Win32BatteryMapper, Win32BiosMapper, Win32CacheMemoryMapper, Win32ComputerSystemMapper, Win32DesktopMonitorMapper, Win32DiskDriveMapper, Win32DiskDriveToDiskPartitionMapper, Win32DiskDriveToPartitionAndLogicalDiskMapper, Win32DiskPartitionMapper, Win32DiskPartitionToLogicalDiskMapper, Win32EnvironmentMapper, Win32LogicalDiskMapper, Win32LogicalDiskToPartitionMapper, Win32NetworkAdapterConfigurationMapper, Win32NetworkAdapterMapper, Win32NetworkAdapterSettingMapper, Win32NetworkAdapterToConfigurationMapper, Win32OperatingSystemMapper, Win32PhysicalMemoryMapper, Win32PnPEntityMapper, Win32PortConnectorMapper, Win32PrinterMapper, Win32ProcessMapper, Win32ProcessorMapper, Win32ProcessorToCacheMemoryMapper, Win32SoundDeviceMapper, Win32UserAccountMapper, Win32VideoControllerMapper
public interface CommonMappingInterface<S>
A common mapping interface for mapping JSON strings to Java objects.
Provides default methods to convert JSON responses
into either a List of objects or a single Optional object.
The default methods in this interface use Gson for JSON deserialization.
- Since:
- 3.0.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionConverts a JSON string into a list of objects of the specified type<S>.mapToObject(@NonNull String json, @NonNull Class<S> objectClass) Converts a JSON string into anOptionalobject of the specified type<S>.
-
Field Details
-
GSON
@NotNull static final @NotNull com.google.gson.Gson GSON
-
-
Method Details
-
mapToList
@NotNull default @NotNull @Unmodifiable List<S> mapToList(@NonNull @NonNull String json, @NonNull @NonNull Class<S> objectClass) Converts a JSON string into a list of objects of the specified type<S>.If the JSON represents a single object, it is returned as a singleton list. If the JSON is null or empty, returns an empty list.
Useful for implementing the mappers of classes which return more than one instance such as the
Win32_NetworkAdapter- Parameters:
json- the JSON string to parse; must not be nullobjectClass- the class of the objects in the list; must not be null- Returns:
- an immutable, non-null list of objects deserialized from JSON.
If the JSON string is empty, it will return an empty unmodifiable list.
If the JSON string does not match the schema of the
objectClass, an immutable list containing exactly 1 object of typeobjectClasswill be returned. If the object allows for null values in its fields, the returned object in the list will have null fields. If null values are disallowed, aNullPointerExceptionmay be thrown. - Throws:
NullPointerException- if the JSON string or the objectClass is nullcom.google.gson.JsonSyntaxException- if the JSON is malformed- Since:
- 3.0.0
-
mapToObject
@NotNull default @NotNull Optional<S> mapToObject(@NonNull @NonNull String json, @NonNull @NonNull Class<S> objectClass) Converts a JSON string into anOptionalobject of the specified type<S>.Useful for implementing the mappers classes which return exactly one instance such as the
Win32_ComputerSystemWMI class- Parameters:
json- the JSON string to parse; must not be nullobjectClass- the class of the object; must not be null- Returns:
- an
Optionalcontaining the deserialized object, orOptional.empty()if the JSON is empty. If the JSON string does not match the schema of the objectClass, anOptionalcontaining an object of typeobjectClasswill be created with null fields. If null values are disallowed, aNullPointerExceptionmay be thrown. - Throws:
com.google.gson.JsonSyntaxException- if the JSON is malformedNullPointerException- if the JSON string or the objectClass is null- Since:
- 3.0.0
-