WeaviateEx.Types.Deserialize (WeaviateEx v0.7.4)
View SourceDeserializes Weaviate response values to Elixir types.
This module provides functions to convert Weaviate API response data
back into rich Elixir types like DateTime, GeoCoordinate, etc.
Usage
You can deserialize individual values with a type hint:
# Date strings
{:ok, dt} = Deserialize.deserialize("2024-01-01T00:00:00Z", :date)
# => {:ok, ~U[2024-01-01 00:00:00Z]}
# GeoCoordinates
{:ok, geo} = Deserialize.deserialize(%{"latitude" => 52.37, "longitude" => 4.90}, :geo_coordinates)
# => {:ok, %GeoCoordinate{latitude: 52.37, longitude: 4.90}}Or deserialize entire property maps with schema hints:
schema = %{"created_at" => :date, "location" => :geo_coordinates}
{:ok, props} = Deserialize.deserialize_properties(raw_props, schema)Type Hints
:date- Parse ISO8601 string to DateTime:geo_coordinates- Parse coordinate map to GeoCoordinate struct:phone_number- Parse phone map to PhoneNumber.Output struct:blob- Parse base64 string to Blob struct:auto- Attempt automatic detection based on value structure
Summary
Functions
Attempts to auto-deserialize all properties in a map.
Deserializes a value based on the provided type hint.
Deserializes a value, raising on error.
Deserializes a map of properties using a schema that maps property names to types.
Deserializes properties, raising on error.
Types
Functions
Attempts to auto-deserialize all properties in a map.
Uses heuristics to detect types automatically.
Deserializes a value based on the provided type hint.
Returns {:ok, value} on success or {:error, reason} on failure.
Examples
iex> Deserialize.deserialize("2024-01-01T00:00:00Z", :date)
{:ok, ~U[2024-01-01 00:00:00Z]}
iex> Deserialize.deserialize(%{"latitude" => 52.37, "longitude" => 4.90}, :geo_coordinates)
{:ok, %GeoCoordinate{latitude: 52.37, longitude: 4.90}}
Deserializes a value, raising on error.
Examples
iex> Deserialize.deserialize!("2024-01-01T00:00:00Z", :date)
~U[2024-01-01 00:00:00Z]
Deserializes a map of properties using a schema that maps property names to types.
Examples
schema = %{
"created_at" => :date,
"location" => :geo_coordinates,
"phone" => :phone_number
}
{:ok, props} = Deserialize.deserialize_properties(raw_props, schema)
Deserializes properties, raising on error.