Skip to content

Conversation

@mpartipilo
Copy link
Collaborator

@mpartipilo mpartipilo commented Jun 6, 2025

Enhance serialization for array properties and introduce GeoCoordinate and PhoneNumber models. Update tests to validate new functionality and ensure compatibility with existing property types.

resolves #30

Copy link

@orca-security-eu orca-security-eu bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

@mpartipilo mpartipilo changed the title Array Properties: Serialization improvements and new GeoCoordinate support Properties: New Arrays and GeoCoordinate support Jun 6, 2025
@mpartipilo mpartipilo marked this pull request as ready for review June 8, 2025 22:33
@mpartipilo mpartipilo changed the title Properties: New Arrays and GeoCoordinate support feat:Properties: New Arrays and GeoCoordinate support Jun 8, 2025
[
.. guids.Select(uuid => new Dictionary<string, string>
{
{ "beacon", $"weaviate://localhost/{uuid}" },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: beacons may optionally specify the name of the collection to which that UUID belongs, in which case they have this format weaviate://localhost/{collection}/{uuid}.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for multi-target references. Those are scheduled for a later beta.

return char.ToLower(str[0]) + str[1..];
}

public static bool IsNativeType(this Type type)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: what is the difference between how native and non-native types are handled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a type is native (primitive) I can just assign it. If it's a well-known object type (guid, geo, some datetime related types) I'm assuming the calling code can handle it directly. If it's an array, I then look into the element type and if it's a native type I can make the same assumption.

Basically, this is to rule out that a type is not a nested object of a custom type, which then needs to be handled as an object or list of objects, and that's scoped for later.

{
object? nestedValue = UnmarshallProperties<ExpandoObject>(subDict);

target[kvp.Key.Capitalize()] = nestedValue ?? subDict;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why do we "capitalize" the key here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention, mostly. It's common for class properties to start with a capital letter. There's no technical requirement for keys to be capitalized.

Usually when the instance of type T is of IDictionary<string, object?> type, we're dealing with a dynamic/ExpandoObject type.


var type = typeof(T);
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanWrite)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: if a property has CanWrite==false, does this mean it can only be set in constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost, it means it's read only OR init only. Some properties can be used for deriving values from other properties, sort of like parameter-less functions.

In a few lines below, we try to assign values to properties via reflection with a case-insensitive best-match, therefore we need to know which properties are writable, since attempting to write to a read only property will throw an exception.

Extras:
- Simplified object retrieval in FetchObjectByID method to return a single object.
- Updated tests to assert against the new object structure.
- Enhanced batch property handling to support array types in DataClient.
- Improved extension methods for better stream handling of native types.
@dirkkul dirkkul merged commit a7c67d3 into mvp Jun 10, 2025
2 checks passed
@dirkkul dirkkul deleted the feat/list_types branch June 10, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants