# How to enforce uniqueness across resources when the validator only receives config (no metadata)?

**URL:** <https://forum.inductiveautomation.com/t/how-to-enforce-uniqueness-across-resources-when-the-validator-only-receives-config-no-metadata/110523>\
**Category:** Ignition 8.3 Early Access\
**Created:** [September 10, 2025, 10:03pm UTC](https://forum.inductiveautomation.com/t/how-to-enforce-uniqueness-across-resources-when-the-validator-only-receives-config-no-metadata/110523 "2025-09-10T22:03:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared\_Diamond](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@Jared\_Diamond](https://forum.inductiveautomation.com/u/Jared_Diamond)\
**Post date:** [September 10, 2025, 10:03pm UTC](https://forum.inductiveautomation.com/t/how-to-enforce-uniqueness-across-resources-when-the-validator-only-receives-config-no-metadata/110523/1 "2025-09-10T22:03:26Z")

</div>

I’m writing a module that defines a resource type. The resource has two config fields (let’s call them `fieldA` and `fieldB`), and the requirement is that no two resources of that type can share the same combination of those values.

To enforce this, I’m registering a validator with the resource type:

```java
public static final ResourceType RESOURCE_TYPE =
    new ResourceType(MODULE_ID, RESOURCE_ID_MY_RESOURCE);

public static final ResourceTypeMeta<MyResource> META =
    ResourceTypeMeta.newBuilder(MyResource.class)
        .resourceType(RESOURCE_TYPE)
        .categoryName("My Settings")
        .withValidator(new MyResourceValidator());

```

The validator looks something like this:

```java
private static class MyResourceValidator implements ResourceValidator<MyResource> {
    @Override
    public Optional<ValidationErrors> validate(MyResource resource) {
        // check if (fieldA, fieldB) combo is unique among
        // all resources of type MyResource
    }
}

```

The issue is that in the `validate` method I only get the config object (`MyResource`). I don’t get the resource’s metadata, such as name or enabled. That makes it tricky to enforce uniqueness, because:

- When updating a resource, my check sees it as a duplicate of itself.

- When fetching the resources with a GET, validation runs for each resource, and each one flags itself as a duplicate. This causes the response to include a JSON list of resources with metadata, but none of them have a `config` field populated.

If I had the resource’s name, I could skip the current one during validation, but since I don’t, every check ends up failing.

Is there a way to access the resource’s name from within `validate`, or is uniqueness supposed to be enforced somewhere else in the API? If the latter, what’s the correct way to do it? Is there another lifecycle hook I can use that fires **before** the resource is created and will still communicate a failed validation check back to the user like the `validate` method does?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 10, 2025, 10:33pm UTC](https://forum.inductiveautomation.com/t/how-to-enforce-uniqueness-across-resources-when-the-validator-only-receives-config-no-metadata/110523/2 "2025-09-10T22:33:14Z")

</div>

> [@Jared\_Diamond](#):
>
> or is uniqueness supposed to be enforced somewhere else in the API?

I'm not sure the kind of uniqueness you are after is considered anywhere at all.

The validation API doesn't seem to consider the idea that validation of a decoded resource would consider any other resources. I don't think it was designed to.

You could maybe explore using a totally custom `ResourceCodec` (via `DefaultResourceTypeMeta.Builder::withCodec`), in which case you are going to be decoding a raw `Resource`, giving you access to some metadata. Not sure how it helps you know what other resources exist and determine the uniqueness of the field pair.

`ValidationException` is a `DecodingException`, throw it during `ResourceCodec::decode` at some point if you're able to determine it's not valid.

---

<div class="post-metadata">

**Author:** ![Jared\_Diamond](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@Jared\_Diamond](https://forum.inductiveautomation.com/u/Jared_Diamond)\
**Post date:** [September 10, 2025, 11:11pm UTC](https://forum.inductiveautomation.com/t/how-to-enforce-uniqueness-across-resources-when-the-validator-only-receives-config-no-metadata/110523/3 "2025-09-10T23:11:37Z")

</div>

I should have provided more context: I have a singleton that has access to this resource’s `NamedResourceHandler`, which is how I’m able to check against existing resources. Thanks for pointing me in the right direction. I’ll take a closer look at using a custom `ResourceCodec`, since it seems to give access to the entire resource during decoding.
