最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - Issue with RangeFilters Metadata Propagation and TypedJson Serialization (Angular) - Stack Overflow

programmeradmin3浏览0评论

I am facing an issue with metadata propagation in my RangeFilters object. I need to copy metadata only to specific instances rather than applying it globally. However, my current approach affects all instances, which causes unwanted behavior.

Additionally, when using TypedJson with jsonMember(String), metadata does not get applied correctly.

Here is an updated example illustrating the problem using a different class:

class DateRangeFilters {
    dateFrom?: Date;
    dateTo?: Date;
}

function PropagateDateFilterMetadata() {
    return function (target: any, propertyKey: string) {
        propagateMetadata(target, propertyKey, DateRangeFilters, "dateFrom");
        propagateMetadata(target, propertyKey, DateRangeFilters, "dateTo");
    };
}

function propagateMetadata(sourceObject: Object, sourceProperty: string, targetClass: any, targetProperty: string) {
    const metadataKeys = Reflect.getMetadataKeys(sourceObject.constructor.prototype, sourceProperty);

    metadataKeys.forEach((key) => {
        const metadataValue = Reflect.getMetadata(key, sourceObject.constructor.prototype, sourceProperty);
        Reflect.defineMetadata(key, metadataValue, targetClass.prototype, targetProperty);
    });
}

// Example usage
class Event {
    @PropagateDateFilterMetadata()
    @DateFormat("yyyyMMdd")
    @jsonMember(String)
    eventDate: DateRangeFilters;
}

Metadata Propagation Issue

I want metadata to be copied only to specific instances of RangeFilters, but it is applied globally to all instances. Is there a way to scope metadata to a particular instance instead of modifying the prototype?

TypedJson Serialization Issue

When using TypedJson with jsonMember(String), metadata is not preserved as expected. Could there be a conflict between Reflect.defineMetadata and TypedJson? How can I ensure metadata is properly copied only to specific instances and make TypedJson correctly handle metadata? Any help would be appreciated!

发布评论

评论列表(0)

  1. 暂无评论